Read the serial number from a YubiKey > 2.2.
421346
def _read_serial(self, may_block):
        

        frame = yubikey_frame.YubiKeyFrame(command = SLOT.DEVICE_SERIAL)
        self._device._write(frame)
        response = self._device._read_response(may_block=may_block)
        if not yubico_util.validate_crc16(response[:6]):
            raise YubiKeyUSBHIDError("Read from device failed CRC check")
        # the serial number is big-endian, although everything else is little-endian
        serial = struct.unpack('>lxxx', response)
        return serial[0]
739144
def iddversiontuple(afile):
    """"""
    def versiontuple(vers):
        """version tuple"""
        return tuple([int(num) for num in vers.split(".")])
    try:
        fhandle = open(afile, 'rb')
    except TypeError:
        fhandle = afile
    line1 = fhandle.readline()
    try:
        line1 = line1.decode('ISO-8859-2')
    except AttributeError:
        pass
    line = line1.strip()
    if line1 == '':
        return (0,)
    vers = line.split()[-1]
    return versiontuple(vers)
1334074
def _read_id_numbers(self):
        """"""
        _byte = self._read_fileng(4)
        _addr = '.'.join([str(_) for _ in _byte])
        return _addr
70207
def serial_number():
    """"""
    sdata = {}
    if os.getuid() == 0:
        try:
            sdata['Serial'] = open('/sys/class/dmi/id/product_serial') \
                .read().strip()
        except:
            for line in os.popen('/usr/sbin/dmidecode -s system-serial-number'):
                sdata['Serial'] = line.strip()
    return sdata
1166562
def read_binary(self, num, item_type='B'):
        """"""
        if 'B' in item_type:
            return self.read(num)

        if item_type[0] in ('@', '=', '<', '>', '!'):
            order = item_type[0]
            item_type = item_type[1:]
        else:
            order = '@'

        return list(self.read_struct(Struct(order + '{:d}'.format(int(num)) + item_type)))
1324920
def ReadSignedBinaryReferences(
      self, binary_id
  ):
    """"""
    binary_key = _SignedBinaryKeyFromID(binary_id)
    try:
      references, timestamp = self.signed_binary_references[binary_key]
    except KeyError:
      raise db.UnknownSignedBinaryError(binary_id)
    return references.Copy(), timestamp.Copy()
536926
def _perform_read(self, addr, size):
        """"""
        return self._machine_controller.read(addr, size, self._x, self._y, 0)
1201589
def _read(self):
        
        request_type = _USB_TYPE_CLASS | _USB_RECIP_INTERFACE | _USB_ENDPOINT_IN
        value = _REPORT_TYPE_FEATURE << 8    # apparently required for YubiKey 1.3.2, but not 2.2.x
        recv = self._usb_handle.controlMsg(request_type,
                                          _HID_GET_REPORT,
                                          _FEATURE_RPT_SIZE,
                                          value = value,
                                          timeout = _USB_TIMEOUT_MS)
        if len(recv) != _FEATURE_RPT_SIZE:
            self._debug("Failed reading %i bytes (got %i) from USB HID YubiKey.\n"
                        % (_FEATURE_RPT_SIZE, recv))
            raise YubiKeyUSBHIDError('Failed reading from USB HID YubiKey')
        data = b''.join(yubico_util.chr_byte(c) for c in recv)
        self._debug("READ  : %s" % (yubico_util.hexdump(data, colorize=True)))
        return data
110315
def _get_key_info(self):
        """"""
        vkey_scan = LoByte(VkKeyScan(self.key))

        return (vkey_scan, MapVirtualKey(vkey_scan, 0), 0)
124196
private int getMagicNumber(InputStream in)
	throws IOException {


		int t = in.read();
		if (t < 0) throw new EOFException("Failed to read magic number");
		int magic = (t & 0xff) << 8;
		t = in.read();
		if (t < 0) throw new EOFException("Failed to read magic number");
		magic += t & 0xff;

		return magic;
	}
62909
def _read_register(self, reg):
        """"""
        self.buf[0] = reg
        with self.i2c_device as i2c:
            i2c.write(self.buf, end=1, stop=False)
            i2c.readinto(self.buf, end=2)
        return self.buf[0] << 8 | self.buf[1]
950302
def _read_capabilities(self):
        

        frame = yubikey_frame.YubiKeyFrame(command=SLOT.YK4_CAPABILITIES)
        self._device._write(frame)
        response = self._device._read_response()
        r_len = yubico_util.ord_byte(response[0])

        # 1 byte length, 2 byte CRC.
        if not yubico_util.validate_crc16(response[:r_len+3]):
            raise YubiKey4_USBHIDError("Read from device failed CRC check")

        return response[1:r_len+1]
1223051
def get_version(release_level=True):
    
    vers = ["%(major)i.%(minor)i.%(micro)i" % __version_info__]
    if release_level and __version_info__['releaselevel'] != 'final':
        vers.append('%(releaselevel)s%(serial)i' % __version_info__)
    return ''.join(vers)
540710
def get_decode_value(self):
        """"""
        if self._store_type == PUBLIC_KEY_STORE_TYPE_HEX:
            value = bytes.fromhex(self._value)
        elif self._store_type == PUBLIC_KEY_STORE_TYPE_BASE64:
            value = b64decode(self._value)
        elif self._store_type == PUBLIC_KEY_STORE_TYPE_BASE85:
            value = b85decode(self._value)
        elif self._store_type == PUBLIC_KEY_STORE_TYPE_JWK:
            # TODO: need to decide on which jwk library to import?
            raise NotImplementedError
        else:
            value = self._value
        return value
89720
def list_keys(ctx, serials, readers):
    
    if readers:
        for reader in list_readers():
            click.echo(reader.name)
        ctx.exit()

    all_descriptors = get_descriptors()
    descriptors = [d for d in all_descriptors if d.key_type != YUBIKEY.SKY]
    skys = len(all_descriptors) - len(descriptors)
    handled_serials = set()
    for dev in list_devices():
        handled = False
        if skys > 0 and dev.key_type == YUBIKEY.SKY:
            skys -= 1
            serial = None
            handled = True
        else:
            serial = dev.serial
            if serial not in handled_serials:
                handled_serials.add(serial)
                matches = [d for d in descriptors if (d.key_type, d.mode)
                           == (dev.driver.key_type, dev.driver.mode)]
                if len(matches) > 0:
                    d = matches[0]
                    descriptors.remove(d)
                    handled = True
        if handled:
            if serials:
                if serial:
                    click.echo(serial)
            else:
                click.echo('{} [{}]{}'.format(
                    dev.device_name,
                    dev.mode,
                    ' Serial: {}'.format(serial) if serial else '')
                )
        dev.close()
        if not descriptors and not skys:
            break
1130957
def serial_number(self):
        """"""
        try:
            return self.data.get('identity').get('serial_num')
        except (KeyError, AttributeError):
            return self.device_status_simple('')
352134
def read_version(group):
    
    version = ('0.1' if 'version' not in group.attrs
               else group.attrs['version'])

    # decode from bytes to str if needed
    if isinstance(version, bytes):
        version = version.decode()

    if not is_supported_version(version):
        raise IOError('version {} is not supported'.format(version))

    return version