fido2.cbor

Minimal CBOR implementation supporting a subset of functionality and types required for FIDO 2 CTAP.

Use the encode(), decode() and decode_from() functions to encode and decode objects to/from CBOR.

DO NOT use the dump_x/load_x functions directly, these will be made private in python-fido2 2.0.

Attributes

CborType

Functions

dump_int(data[, mt])

dump_bool(data)

dump_list(data)

dump_dict(data)

dump_bytes(data)

dump_text(data)

load_int(ai, data)

load_nint(ai, data)

load_bool(ai, data)

load_bytes(ai, data)

load_text(ai, data)

load_array(ai, data)

load_map(ai, data)

encode(data)

Encodes data to a CBOR byte string.

decode_from(data)

Decodes a CBOR-encoded value from the start of a byte string.

decode(data)

Decodes data from a CBOR-encoded byte string.

Module Contents

fido2.cbor.CborType
fido2.cbor.dump_int(data, mt=0)[source]
Parameters:
Return type:

bytes

fido2.cbor.dump_bool(data)[source]
Parameters:

data (bool)

Return type:

bytes

fido2.cbor.dump_list(data)[source]
Parameters:

data (Sequence[CborType])

Return type:

bytes

fido2.cbor.dump_dict(data)[source]
Parameters:

data (Mapping[CborType, CborType])

Return type:

bytes

fido2.cbor.dump_bytes(data)[source]
Parameters:

data (bytes)

Return type:

bytes

fido2.cbor.dump_text(data)[source]
Parameters:

data (str)

Return type:

bytes

fido2.cbor.load_int(ai, data)[source]
Parameters:
Return type:

Tuple[int, bytes]

fido2.cbor.load_nint(ai, data)[source]
Parameters:
Return type:

Tuple[int, bytes]

fido2.cbor.load_bool(ai, data)[source]
Parameters:
Return type:

Tuple[bool, bytes]

fido2.cbor.load_bytes(ai, data)[source]
Parameters:
Return type:

Tuple[bytes, bytes]

fido2.cbor.load_text(ai, data)[source]
Parameters:
Return type:

Tuple[str, bytes]

fido2.cbor.load_array(ai, data)[source]
Parameters:
Return type:

Tuple[Sequence[CborType], bytes]

fido2.cbor.load_map(ai, data)[source]
Parameters:
Return type:

Tuple[Mapping[CborType, CborType], bytes]

fido2.cbor.encode(data)[source]

Encodes data to a CBOR byte string.

Parameters:

data (CborType)

Return type:

bytes

fido2.cbor.decode_from(data)[source]

Decodes a CBOR-encoded value from the start of a byte string.

Additional data after a valid CBOR object is returned as well.

Returns:

The decoded object, and any remaining data.

Parameters:

data (bytes)

Return type:

Tuple[Any, bytes]

fido2.cbor.decode(data)[source]

Decodes data from a CBOR-encoded byte string.

Also validates that no extra data follows the encoded object.

Return type:

CborType