Class CBOREncoder
java.lang.Object
org.bouncycastle.cbor.CBOREncoder
An encoder producing Deterministically Encoded CBOR (RFC 8949, Sections 4.2.1 and
4.2.2). Integer arguments, lengths and tag numbers are always emitted in their
shortest form, and only definite-length items can be produced, so any output of this
class is deterministically encoded by construction.
The encoder does not enforce map key ordering itself - callers writing maps are responsible for presenting keys in bytewise lexicographic order of their encodings. The structures defined for C509 (draft-ietf-cose-cbor-encoded-cert-20) use no maps.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidwriteArrayHeader(int count) Write an array header (major type 4) for an array of the given number of elements.voidwriteBoolean(boolean value) Write a boolean simple value (0xf4 or 0xf5).voidwriteByteString(byte[] bytes) Write a byte string (major type 2).voidwriteByteString(byte[] bytes, int off, int len) Write a byte string (major type 2) from a slice of an array.voidwriteEncoded(byte[] encodedItem) Write a complete data item that has already been encoded.voidwriteInteger(long value) Write an integer (major type 0 or 1 according to sign).voidwriteInteger(BigInteger value) Write an integer (major type 0 or 1 according to sign) of any magnitude CBOR supports (-2^64 to 2^64-1).voidwriteMapHeader(int count) Write a map header (major type 5) for a map of the given number of key/value pairs.voidWrite the simple value null (0xf6).voidwriteTag(long tagNumber) Write a tag (major type 6).voidwriteTextString(String text) Write a text string (major type 3), encoded as UTF-8.voidWrite the simple value undefined (0xf7).voidwriteUnsignedInteger(long value) Write an unsigned integer (major type 0).
-
Constructor Details
-
CBOREncoder
Base constructor.- Parameters:
out- the stream the CBOR encoding is written to.
-
-
Method Details
-
writeUnsignedInteger
Write an unsigned integer (major type 0).- Parameters:
value- the value, which must be non-negative.- Throws:
IOException
-
writeInteger
Write an integer (major type 0 or 1 according to sign).- Throws:
IOException
-
writeInteger
Write an integer (major type 0 or 1 according to sign) of any magnitude CBOR supports (-2^64 to 2^64-1).- Throws:
IOException
-
writeByteString
Write a byte string (major type 2).- Throws:
IOException
-
writeByteString
Write a byte string (major type 2) from a slice of an array.- Throws:
IOException
-
writeTextString
Write a text string (major type 3), encoded as UTF-8.- Throws:
IOException
-
writeArrayHeader
Write an array header (major type 4) for an array of the given number of elements. The elements themselves are written by the following calls.- Throws:
IOException
-
writeMapHeader
Write a map header (major type 5) for a map of the given number of key/value pairs. The keys and values themselves are written by the following calls, and must be presented in deterministic key order.- Throws:
IOException
-
writeTag
Write a tag (major type 6). The tag content is written by the following call.- Throws:
IOException
-
writeBoolean
Write a boolean simple value (0xf4 or 0xf5).- Throws:
IOException
-
writeNull
-
writeUndefined
Write the simple value undefined (0xf7).- Throws:
IOException
-
writeEncoded
Write a complete data item that has already been encoded. The caller is responsible for the item being deterministically encoded - typically it was produced by this class or validated byCBORDecoder.readEncodedItem().- Throws:
IOException
-