Implementation of the Yubico OTP algorithm. This can generate and parse OTP structures.
>>> from binascii import unhexlify
>>> key = b'0123456789abcdef'
>>> otp = OTP(unhexlify(b'0123456789ab'), 5, 0x0153f8, 0, 0x1234)
>>> _ = repr(otp) # coverage
>>> _ = str(otp) # coverage
>>> token = encode_otp(otp, key, b'cclngiuv')
>>> token == b'cclngiuvttkhthcilurtkerbjnnkljfkjccklkhl'
True
>>> public_id, otp2 = decode_otp(token, key)
>>> public_id == b'cclngiuv'
True
>>> otp2 == otp
True
Decodes a modhex-encoded Yubico OTP token and returns the public ID and the unpacked OTP object.
Parameters: |
|
---|---|
Returns: | The public ID in its modhex-encoded form and the OTP structure. |
Return type: | (bytes, OTP) |
Raises : | ValueError if the string can not be decoded. |
Raises : | CRCError if the checksum on the decrypted data is incorrect. |
Encodes an OTP structure, encrypts it with the given key and returns the modhex-encoded token.
Parameters: |
|
---|---|
Raises : | ValueError if any parameters are out of range. |
A single YubiKey OTP. This is typically instantiated by parsing an encoded OTP.
Parameters: |
|
---|
A simulated YubiKey device. This can be used to generate a sequence of Yubico OTP tokens.
Parameters: |
|
---|