Class Cbor
java.lang.Object
com.iizix.server.user.passkey.Cbor
A decoder for the CBOR (RFC 8949) a WebAuthn authenticator sends: the attestation object, the credential public key in COSE form and the extensions of the authenticator data (CC-LOGIN-L8-PASSKEYS). It reads the data of a peer, so it is strict and bounded: definite lengths only (CTAP2 canonical CBOR has no other), no tag, a nesting of at most
MAX_DEPTH, at most MAX_ITEMS items, every length checked against the bytes that are left, no duplicate key in a map, and text that is valid UTF-8. Anything else is a PasskeyException.The values are returned as Long (both integer types; an integer beyond a long is refused), byte [], String, List<Object>, Map<Object,Object> in the order of the data, Boolean, Double and null (null and undefined).
- Author:
- Christopher Mindus
Field Summary
FieldsConstructor Summary
ConstructorsConstructorDescriptionCbor(byte[] data, int offset, int length) Creates a reader on a part of a byte array.Method Summary
Field Details
MAX_DEPTH
public static final int MAX_DEPTHThe deepest nesting of arrays and maps that is read.- See Also:
MAX_ITEMS
public static final int MAX_ITEMSThe most items (values, of any kind and at any depth) that are read from one input.- See Also:
Constructor Details
Cbor
public Cbor(byte[] data, int offset, int length) Creates a reader on a part of a byte array.- Parameters:
data- The data.offset- The offset of the first byte.length- The count of bytes.- Throws:
NullPointerException- Ifdatais null.IndexOutOfBoundsException- If the part is not inside the array.
Method Details
decode
Decodes data that is exactly one CBOR value.- Parameters:
data- The data.- Returns:
- The value.
- Throws:
NullPointerException- Ifdatais null.PasskeyException- If the data is not one well-formed value of the kinds read, or bytes follow it.
getPosition
public int getPosition()Gets the position of the next byte to read.- Returns:
- The position in the array.
isAtEnd
public boolean isAtEnd()Checks if all the data has been read.- Returns:
- true when no byte is left.
read
Reads the next value.- Returns:
- The value.
- Throws:
PasskeyException- If the data is not a well-formed value of the kinds read.