Class Cbor

java.lang.Object
com.iizix.server.user.passkey.Cbor

public final class Cbor extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The deepest nesting of arrays and maps that is read.
    static final int
    The most items (values, of any kind and at any depth) that are read from one input.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Cbor(byte[] data, int offset, int length)
    Creates a reader on a part of a byte array.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    decode(byte[] data)
    Decodes data that is exactly one CBOR value.
    int
    Gets the position of the next byte to read.
    boolean
    Checks if all the data has been read.
    Reads the next value.
  • Field Details

    • MAX_DEPTH

      public static final int MAX_DEPTH
      The deepest nesting of arrays and maps that is read.
      See Also:
    • MAX_ITEMS

      public static final int MAX_ITEMS
      The 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 - If data is null.
      IndexOutOfBoundsException - If the part is not inside the array.
  • Method Details

    • decode

      public static Object decode(byte[] data) throws PasskeyException
      Decodes data that is exactly one CBOR value.
      Parameters:
      data - The data.
      Returns:
      The value.
      Throws:
      NullPointerException - If data is 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

      public Object read() throws PasskeyException
      Reads the next value.
      Returns:
      The value.
      Throws:
      PasskeyException - If the data is not a well-formed value of the kinds read.