Debian Codegraph @

addons/auth_passkey/_vendor/webauthn/helpers/encode_cbor.py

raw
1 from typing import Any
2
3 import cbor2
4
5 from .exceptions import InvalidCBORData
6
7
8 def encode_cbor(val: Any) -> bytes:
9 """
10 Attempt to encode data into CBOR.
11
12 Raises:
13 `helpers.exceptions.InvalidCBORData` if data cannot be decoded
14 """
15 try:
16 to_return = cbor2.dumps(val)
17 except Exception as exc:
18 raise InvalidCBORData("Data could not be encoded to CBOR") from exc
19
20 return to_return