Set or change the PIN code.

    The FIDO2 PIN must be at least 4 characters long, and supports any type
    of alphanumeric characters.

    On YubiKey FIPS, a PIN can be set for FIDO U2F. That PIN must be at least
    6 characters long.
972906
def set_pin(ctx, pin, new_pin, u2f):
    

    controller = ctx.obj['controller']
    is_fips = controller.is_fips

    if is_fips and not u2f:
        ctx.fail('This is a YubiKey FIPS. To set the U2F PIN, pass the --u2f '
                 'option.')

    if u2f and not is_fips:
        ctx.fail('This is not a YubiKey FIPS, and therefore does not support a '
                 'U2F PIN. To set the FIDO2 PIN, remove the --u2f option.')

    def prompt_new_pin():
        return click.prompt(
                    'Enter your new PIN', default='', hide_input=True,
                    show_default=False, confirmation_prompt=True, err=True)

    def change_pin(pin, new_pin):
        if pin is not None:
            _fail_if_not_valid_pin(ctx, pin, is_fips)
        _fail_if_not_valid_pin(ctx, new_pin, is_fips)
        try:
            if is_fips:
                try:
                    # Failing this with empty current PIN does not cost a retry
                    controller.change_pin(old_pin=pin or '', new_pin=new_pin)
                except ApduError as e:
                    if e.code == SW.WRONG_LENGTH:
                        pin = _prompt_current_pin()
                        _fail_if_not_valid_pin(ctx, pin, is_fips)
                        controller.change_pin(old_pin=pin, new_pin=new_pin)
                    else:
                        raise

            else:
                controller.change_pin(old_pin=pin, new_pin=new_pin)

        except CtapError as e:
            if e.code == CtapError.ERR.PIN_INVALID:
                ctx.fail('Wrong PIN.')
            if e.code == CtapError.ERR.PIN_AUTH_BLOCKED:
                ctx.fail(
                    'PIN authentication is currently blocked. '
                    'Remove and re-insert the YubiKey.')
            if e.code == CtapError.ERR.PIN_BLOCKED:
                ctx.fail('PIN is blocked.')
            if e.code == CtapError.ERR.PIN_POLICY_VIOLATION:
                ctx.fail('New PIN is too long.')
            logger.error('Failed to change PIN', exc_info=e)
            ctx.fail('Failed to change PIN.')

        except ApduError as e:
            if e.code == SW.VERIFY_FAIL_NO_RETRY:
                ctx.fail('Wrong PIN.')

            if e.code == SW.AUTH_METHOD_BLOCKED:
                ctx.fail('PIN is blocked.')

            logger.error('Failed to change PIN', exc_info=e)
            ctx.fail('Failed to change PIN.')

    def set_pin(new_pin):
        _fail_if_not_valid_pin(ctx, new_pin, is_fips)
        try:
            controller.set_pin(new_pin)
        except CtapError as e:
            if e.code == CtapError.ERR.PIN_POLICY_VIOLATION:
                ctx.fail('PIN is too long.')
            logger.error('Failed to set PIN', exc_info=e)
            ctx.fail('Failed to set PIN')

    if pin and not controller.has_pin:
        ctx.fail('There is no current PIN set. Use --new-pin to set one.')

    if controller.has_pin and pin is None and not is_fips:
        pin = _prompt_current_pin()

    if not new_pin:
        new_pin = prompt_new_pin()

    if controller.has_pin:
        change_pin(pin, new_pin)
    else:
        set_pin(new_pin)
508557
function Yubikey(clientId, secretKey) {
  this.clientId = clientId || process.env['YUBIKEY_CLIENT_ID'];
  this.secretKey = secretKey || process.env['YUBIKEY_SECRET_KEY'];

  if (!(this.clientId && this.secretKey)) {
    throw new Error("need client id and secret key");
  }
}
1238353
def idempotency_key=(idempotency_key)
      if idempotency_key.nil?
        fail ArgumentError, "idempotency_key cannot be nil"
      end

      if idempotency_key.to_s.length > 192
        fail ArgumentError, "invalid value for 'idempotency_key', the character length must be smaller than or equal to 192."
      end

      if idempotency_key.to_s.length < 1
        fail ArgumentError, "invalid value for 'idempotency_key', the character length must be great than or equal to 1."
      end

      @idempotency_key = idempotency_key
    end
72866
def set_conversion(self, idx):
        

        # First, determine the name
        if self.conv_begin:
            name = self.format[self.conv_begin:idx]
        else:
            name = self.format[idx]

        # Next, add the status code modifiers, as needed
        if self.codes:
            self.modifier.set_codes(self.codes, self.reject)

        # Append the conversion to the format
        self.fmt.append_conv(self.fmt._get_conversion(name, self.modifier))

        # Clear the conversion data
        self.param_begin = None
        self.conv_begin = None
        self.modifier = None
        self.codes = []
        self.reject = False
        self.code_last = False
1247700
def modify_key_parity(key):
    
    validated_key = b''
    for byte in key:
        if parityOf(int(byte)) == -1:
            byte_candidate = int(byte) + 1 
            while parityOf(byte_candidate) == -1:
                byte_candidate = divmod(byte_candidate + 1, 256)[1]
            validated_key += bytes([byte_candidate])

        else:
            validated_key += bytes([byte])
    return validated_key
1054400
def to_string(self):
        
        #define UID_SIZE		6	/* Size of secret ID field */
        #define FIXED_SIZE              16      /* Max size of fixed field */
        #define KEY_SIZE                16      /* Size of AES key */
        #define KEY_SIZE_OATH           20      /* Size of OATH-HOTP key (key field + first 4 of UID field) */
        #define ACC_CODE_SIZE           6       /* Size of access code to re-program device */
        #
        #struct config_st {
        #    unsigned char fixed[FIXED_SIZE];/* Fixed data in binary format */
        #    unsigned char uid[UID_SIZE];    /* Fixed UID part of ticket */
        #    unsigned char key[KEY_SIZE];    /* AES key */
        #    unsigned char accCode[ACC_CODE_SIZE]; /* Access code to re-program device */
        #    unsigned char fixedSize;        /* Number of bytes in fixed field (0 if not used) */
        #    unsigned char extFlags;         /* Extended flags */
        #    unsigned char tktFlags;         /* Ticket configuration flags */
        #    unsigned char cfgFlags;         /* General configuration flags */
        #    unsigned char rfu[2];           /* Reserved for future use */
        #    unsigned short crc;             /* CRC16 value of all fields */
        #};
        t_rfu = 0

        first = struct.pack('<16s6s16s6sBBBBH',
                            self.fixed,
                            self.uid,
                            self.key,
                            self.access_code,
                            len(self.fixed),
                            self.extended_flags.to_integer(),
                            self.ticket_flags.to_integer(),
                            self.config_flags.to_integer(),
                            t_rfu
                            )

        crc = 0xffff - yubico_util.crc16(first)

        second = first + struct.pack('<H', crc) + self.unlock_code
        return second
475008
def encode_max_apdu_length_accepted(arg):
    """"""
    for i in range(5, -1, -1):
        if (arg >= _max_apdu_length_encoding[i]):
            return i

    raise ValueError("invalid max APDU length accepted: %r" % (arg,))
217300
def uuid2buid(value):
    
    if six.PY3:  # pragma: no cover
        return urlsafe_b64encode(value.bytes).decode('utf-8').rstrip('=')
    else:
        return six.text_type(urlsafe_b64encode(value.bytes).rstrip('='))
461737
public static byte[] setMode(byte pinId, Pin.Mode mode) {
        if (mode == Pin.Mode.UNSUPPORTED) {
            throw new IllegalArgumentException("Cannot set unsupported mode to pin " + pinId);
        }
        return new byte[]{SET_PIN_MODE, pinId, (byte) mode.ordinal()};
    }
334268
def add_cnt_64bit(self,oid,value,label=None):
		""""""
		# Truncate integer to 64bits ma,x
		self.add_oid_entry(oid,'Counter64',int(value)%18446744073709551615,label=label)
1007198
def add_cnt_32bit(self,oid,value,label=None):
		""""""
		# Truncate integer to 32bits ma,x
		self.add_oid_entry(oid,'Counter32',int(value)%4294967296,label=label)
1340177
private void validateIfdFP(IFD ifd, int p) {
    IfdTags metadata = ifd.getMetadata();

    checkRequiredTag(metadata, "ImageDescription", 1);
    checkRequiredTag(metadata, "StripOffsets", 1);
    if (p == 1 || p == 2) {
      checkRequiredTag(metadata, "StripOffsets", 1, new long[]{0});
    }
    checkRequiredTag(metadata, "NewSubfileType", 1);
    checkRequiredTag(metadata, "ImageLength", 1);
    checkRequiredTag(metadata, "ImageWidth", 1);
    checkRequiredTag(metadata, "StripOffsets", 1);
    if (p == 0) {
      checkRequiredTag(metadata, "Orientation", 1, new long[]{1,4,5,8});
    } else {
      checkRequiredTag(metadata, "Orientation", 1, new long[]{1});
    }
    checkRequiredTag(metadata, "StripBYTECount", 1);
    checkRequiredTag(metadata, "XResolution", 1);
    checkRequiredTag(metadata, "YResolution", 1);
    checkRequiredTag(metadata, "PlanarConfiguration", 1, new long[]{2});
    if (p == 1 || p == 2) {
      checkRequiredTag(metadata, "ResolutionUnit", 1, new long[]{2, 3});
      checkRequiredTag(metadata, "NumberOfInks", 1, new long[]{4});
    }
  }
1183577
def write_points(self, fid):
        
        for nr, point in enumerate(self.Points):
            fid.write(
                'Point({0}) = {{{1}, {2}, 0, {3}}};\n'.format(
                    nr + 1, point[0], point[1], self.Charlengths[nr]))
24972
def int2ap(num):
    """"""
    val = ''
    ap = 'ABCDEFGHIJKLMNOP'
    num = int(abs(num))
    while num:
        num, mod = divmod(num, 16)
        val += ap[mod:mod + 1]
    return val
447560
def uuid_to_uid(uuid)
      uuid = Integer(uuid)
      if uuid >= 0 && uuid <= MAX_UUID
        10_000 + uuid
      else
        raise RangeError, "#{uuid} is not within (0..#{MAX_UUID})"
      end
    end
693485
def pin_to_ipfs(
    manifest: Manifest, *, backend: BaseIPFSBackend, prettify: Optional[bool] = False
) -> List[Dict[str, str]]:
    
    contents = format_manifest(manifest, prettify=prettify)

    with tempfile.NamedTemporaryFile() as temp:
        temp.write(to_bytes(text=contents))
        temp.seek(0)
        return backend.pin_assets(Path(temp.name))
710131
def customPRF512(key, amac, smac, anonce, snonce):
    """"""
    A = b"Pairwise key expansion"
    B = b"".join(sorted([amac, smac]) + sorted([anonce, snonce]))

    blen = 64
    i = 0
    R = b''
    while i <= ((blen * 8 + 159) / 160):
        hmacsha1 = hmac.new(key, A + chb(0x00) + B + chb(i), hashlib.sha1)
        i += 1
        R = R + hmacsha1.digest()
    return R[:blen]