Class Cbor

java.lang.Object
com.yubico.yubikit.fido.Cbor

public class Cbor extends Object
Provides canonical CBOR encoding and decoding.

Only a small subset of CBOR is implemented, sufficient for CTAP2 functionality.

Note that while any integer type can be encoded into canonical CBOR, but all CBOR integers will decode to an int. Thus, numeric map keys can use any integer type (byte, short, int, long) when encoding to send to a device, but any response will have ints for keys.

  • Constructor Details

    • Cbor

      public Cbor()
  • Method Details

    • encode

      public static byte[] encode(Object value)
      Encodes an object into canonical CBOR.
      Parameters:
      value - the Object to encode.
      Returns:
      CBOR encoded bytes.
    • encodeTo

      public static void encodeTo(OutputStream stream, @Nullable Object value) throws IOException
      Encodes an object into canonical CBOR, to an OutputStream.
      Parameters:
      stream - the output stream to write to
      value - the Object to encode.
      Throws:
      IOException - A communication error in the transport layer.
    • decode

      @Nullable public static Object decode(byte[] data, int offset, int length)
      Decodes an Object from CBOR data.
      Parameters:
      data - The CBOR encoded byte array.
      offset - The offset of where the CBOR encoded data is in the given byte array.
      length - The length of CBOR encoded data.
      Returns:
      The decoded Object.
    • decode

      @Nullable public static Object decode(byte[] data)
      Decodes an Object from CBOR data.
      Parameters:
      data - The CBOR encoded byte array.
      Returns:
      The decoded Object.
    • decodeFrom

      @Nullable public static Object decodeFrom(ByteBuffer buf)
      Decodes a single Object from a ByteBuffer containing CBOR encoded data at the buffers current position. The position will be updated to point to the end of the CBOR data.
      Parameters:
      buf - the ByteBuffer from where the Object should be decoded.
      Returns:
      The decoded object.