u2flib_host/device.py
def send_apdu(self, ins, p1=0, p2=0, data=b''):
        """
        Sends an APDU to the device, and waits for a response.
        """
        if data is None:
            data = b''
        elif isinstance(data, int):
            data = int2byte(data)

        size = len(data)
        l0 = size >> 16 & 0xff
        l1 = size >> 8 & 0xff
        l2 = size & 0xff
        apdu_data = struct.pack('B B B B B B B %is B B' % size,
                                0, ins, p1, p2, l0, l1, l2, data, 0x00, 0x00)
        try:
            resp = self._do_send_apdu(apdu_data)
        except Exception as e:
            # TODO Use six.reraise if/when Six becomes an agreed dependency.
            raise exc.DeviceError(e)
        status = struct.unpack('>H', resp[-2:])[0]
        data = resp[:-2]
        if status != APDU_OK:
            raise exc.APDUError(status)
        return data
def send_apdu(self, ins, p1=0, p2=0, data=b''):
        if data is None:
            data = b''
        elif isinstance(data, int):
            data = int2byte(data)

        size = len(data)
        l0 = size >> 16 & 0xff
        l1 = size >> 8 & 0xff
        l2 = size & 0xff
        apdu_data = struct.pack('B B B B B B B %is B B' % size,
                                0, ins, p1, p2, l0, l1, l2, data, 0x00, 0x00)
        try:
            resp = self._do_send_apdu(apdu_data)
        except Exception as e:
            # TODO Use six.reraise if/when Six becomes an agreed dependency.
            raise exc.DeviceError(e)
        status = struct.unpack('>H', resp[-2:])[0]
        data = resp[:-2]
        if status != APDU_OK:
            raise exc.APDUError(status)
        return data
def send_apdu ( self , ins , p1 = 0 , p2 = 0 , data = b'' ) : if data is None : data = b'' elif isinstance ( data , int ) : data = int2byte ( data ) size = len ( data ) l0 = size >> 16 & 0xff l1 = size >> 8 & 0xff l2 = size & 0xff apdu_data = struct . pack ( 'B B B B B B B %is B B' % size , 0 , ins , p1 , p2 , l0 , l1 , l2 , data , 0x00 , 0x00 ) try : resp = self . _do_send_apdu ( apdu_data ) except Exception as e : # TODO Use six.reraise if/when Six becomes an agreed dependency. raise exc . DeviceError ( e ) status = struct . unpack ( '>H' , resp [ - 2 : ] ) [ 0 ] data = resp [ : - 2 ] if status != APDU_OK : raise exc . APDUError ( status ) return data
Sends an APDU to the device, and waits for a response.
Sends an APDU to the device and waits for a response .