Package org.webpki.cbor
Class CBORDecoder
java.lang.Object
org.webpki.cbor.CBORDecoder
CBOR decoder class.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorsConstructorDescriptionCBORDecoder
(InputStream inputStream, int options, int maxInputLength) Create a customized CBOR decoder. -
Method Summary
Modifier and TypeMethodDescriptionstatic CBORObject
decode
(byte[] cbor) Decode CBOR data.Decode CBOR data with options.int
Get CBOR decoder byte count.
-
Field Details
-
SEQUENCE_MODE
public static final int SEQUENCE_MODE- See Also:
-
LENIENT_MAP_DECODING
public static final int LENIENT_MAP_DECODING- See Also:
-
LENIENT_NUMBER_DECODING
public static final int LENIENT_NUMBER_DECODING- See Also:
-
REJECT_INVALID_FLOATS
public static final int REJECT_INVALID_FLOATS- See Also:
-
-
Constructor Details
-
CBORDecoder
Create a customized CBOR decoder.This constructor presumes that the actual decoding is performed by one or more (for sequences only) calls to
decodeWithOptions()
.Customization is provided through an
options
parameter. Multiple options can be combined using the binary OR-operator ("|
"). A zero (0) sets the decoder default mode. The options are defined by the following constants:If theSEQUENCE_MODE
option is defined, the following apply:- The decoder returns after having decoded a single CBOR object, while preparing for the next object.
- If no data is found (EOF),
null
is returned (empty sequences are permitted).
By default, the decoder requires that CBOR maps conform to the Deterministic Encoding rules. TheLENIENT_MAP_DECODING
option forces the decoder to accept CBOR maps with arbitrary key ordering. Note that duplicate keys still cause aCBORException
to be thrown.By default, the decoder requires that CBOR numbers conform to the Deterministic Encoding rules. TheLENIENT_NUMBER_DECODING
option forces the decoder to accept different representations of CBORint
,bigint
, andfloat
items, only limited by RFC 8949.By default, the decoder supportsNaN
andInfinity
values. In case these variants are not applicable for the application in question, theREJECT_INVALID_FLOATS
option causes such numbers to throw aCBORException
.Exceeding
maxInputLength
throws aCBORException
. It is recommendable setting this as low as possible, since malformed CBOR objects may request any amount of memory.- Parameters:
inputStream
- Stream holding CBOR data.options
- The decoder options.maxInputLength
- Upper limit in bytes.- See Also:
-
-
Method Details
-
decodeWithOptions
Decode CBOR data with options.- Returns:
CBORObject
ornull
(for EOF sequences only).- Throws:
CBORException
- For decoding errors.
-
getByteCount
public int getByteCount()Get CBOR decoder byte count.This is equivalent to the position of the next item to be read.
- Returns:
- The number of bytes read so far.
-
decode
Decode CBOR data.This conveniance method is identical to:
new CBORDecoder(new ByteArrayInputStream(cbor), 0, cbor.length) .decodeWithOptions();
- Parameters:
cbor
- CBOR binary data holding exactly one CBOR object.- Returns:
CBORObject
- Throws:
CBORException
- For decoding errors.
-