fido2.utils

Various utility functions.

This module contains various functions used throughout the rest of the project.

Functions

sha256(data)

Produces a SHA256 hash of the input.

hmac_sha256(key, data)

Performs an HMAC-SHA256 operation on the given data, using the given key.

bytes2int(value)

Parses an arbitrarily sized integer from a byte string.

int2bytes(value[, minlen])

Encodes an int as a byte string.

websafe_decode(data)

Decodes a websafe-base64 encoded string.

websafe_encode(data)

Encodes a byte string into websafe-base64 encoding.

Module Contents

fido2.utils.sha256(data)[source]

Produces a SHA256 hash of the input.

Parameters:

data (bytes) – The input data to hash.

Returns:

The resulting hash.

Return type:

bytes

fido2.utils.hmac_sha256(key, data)[source]

Performs an HMAC-SHA256 operation on the given data, using the given key.

Parameters:
  • key (bytes) – The key to use.

  • data (bytes) – The input data to hash.

Returns:

The resulting hash.

Return type:

bytes

fido2.utils.bytes2int(value)[source]

Parses an arbitrarily sized integer from a byte string.

Parameters:

value (bytes) – A byte string encoding a big endian unsigned integer.

Returns:

The parsed int.

Return type:

int

fido2.utils.int2bytes(value, minlen=-1)[source]

Encodes an int as a byte string.

Parameters:
  • value (int) – The integer value to encode.

  • minlen (int) – An optional minimum length for the resulting byte string.

Returns:

The value encoded as a big endian byte string.

Return type:

bytes

fido2.utils.websafe_decode(data)[source]

Decodes a websafe-base64 encoded string. See: “Base 64 Encoding with URL and Filename Safe Alphabet” from Section 5 in RFC4648 without padding.

Parameters:

data (Union[str, bytes]) – The input to decode.

Returns:

The decoded bytes.

Return type:

bytes

fido2.utils.websafe_encode(data)[source]

Encodes a byte string into websafe-base64 encoding.

Parameters:

data (bytes) – The input to encode.

Returns:

The encoded string.

Return type:

str