Package-level declarations

Types

Link copied to clipboard
object Asn1

Namespace object for ASN.1 builder DSL functions and utility functions for creating ASN.1 primitives

Link copied to clipboard

Class Providing a DSL for creating arbitrary ASN.1 structures. You will almost certainly never use it directly, but rather use it as follows:

Properties

Link copied to clipboard

the number of bits required to represent this number

Functions

Link copied to clipboard

Transforms this Asn1Primitive' into an Asn1BitString, assuming it was encoded as BIT STRING

Link copied to clipboard

transforms this Asn1Primitive into an Asn1String subtype based on its tag

Link copied to clipboard
inline fun <T> Asn1Primitive.decode(assertTag: Asn1Element.Tag, transform: (content: ByteArray) -> T): T
inline fun <T> Asn1Primitive.decode(assertTag: ULong, transform: (content: ByteArray) -> T): T

Generic decoding function. Verifies that this Asn1Primitive's tag matches assertTag and transforms its content as per transform

Link copied to clipboard

Decodes an unsigned Asn1Integer from bytes using varint encoding as used within ASN.1: groups of seven bits are encoded into a byte, while the highest bit indicates if more bytes are to come. Trailing bytes are ignored.

Decodes an ASN.1 unsigned varint to a Asn1Integer, copying all bytes from the source into a ByteArray.

Link copied to clipboard

Decodes an UInt from bytes using varint encoding as used within ASN.1: groups of seven bits are encoded into a byte, while the highest bit indicates if more bytes are to come. Trailing bytes are ignored.

Decodes an ASN.1 unsigned varint to an UInt, copying all bytes from the source into a ByteArray.

Link copied to clipboard

Decodes an ULong from bytes using varint encoding as used within ASN.1: groups of seven bits are encoded into a byte, while the highest bit indicates if more bytes are to come. Trailing bytes are ignored.

Decodes an ASN.1 unsigned varint to an ULong, copying all bytes from the source into a ByteArray.

Link copied to clipboard

Decodes a Asn1Integer from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 INTEGER

Decodes a Boolean from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 BOOLEAN

Decodes a signed Int from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 INTEGER

Decodes a signed Long from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 INTEGER

Decodes a String from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 STRING (any kind)

Decodes a UInt from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 INTEGER

Decodes a ULong from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 INTEGER

fun Instant.Companion.decodeGeneralizedTimeFromAsn1ContentBytes(bytes: ByteArray): Instant

Decodes an Instant from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 GENERALIZED TIME

Link copied to clipboard
inline fun <T> Asn1Primitive.decodeOrNull(tag: ULong, transform: (content: ByteArray) -> T): T?

Exception-free version of decode

Link copied to clipboard
fun Asn1Primitive.decodeToAsn1Integer(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): Asn1Integer

Decode the Asn1Primitive as a Asn1Integer

Link copied to clipboard
inline fun Asn1Primitive.decodeToAsn1IntegerOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): Asn1Integer?

Exception-free version of decodeToAsn1Integer

Link copied to clipboard
fun Asn1Primitive.decodeToBoolean(assertTag: Asn1Element.Tag = Asn1Element.Tag.BOOL): Boolean

decodes this Asn1Primitive's content into an Boolean. assertTag defaults to Asn1Element.Tag.BOOL, but can be overridden (for implicitly tagged booleans, for example)

Link copied to clipboard
fun Asn1Primitive.decodeToBooleanOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.BOOL): Boolean?

Exception-free version of decodeToBoolean

Link copied to clipboard

decodes this Asn1Primitive's content into an Instant if it is encoded as UTC TIME or GENERALIZED TIME

Link copied to clipboard

Exception-free version of decodeToInstant

Link copied to clipboard
fun Asn1Primitive.decodeToInt(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): Int

decodes this Asn1Primitive's content into an Int. assertTag defaults to Asn1Element.Tag.INT, but can be overridden (for implicitly tagged integers, for example)

Link copied to clipboard
fun Asn1Primitive.decodeToIntOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): Int?

Exception-free version of decodeToInt

Link copied to clipboard
fun Asn1Primitive.decodeToLong(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): Long

decodes this Asn1Primitive's content into a Long. assertTag defaults to Asn1Element.Tag.INT, but can be overridden (for implicitly tagged longs, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToLongOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): Long?

Exception-free version of decodeToLong

Link copied to clipboard

Decodes this Asn1Primitive's content into a String.

Link copied to clipboard

Exception-free version of decodeToString

Link copied to clipboard
fun Asn1Primitive.decodeToUInt(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): UInt

decodes this Asn1Primitive's content into an UInt√. assertTag defaults to Asn1Element.Tag.INT, but can be overridden (for implicitly tagged unsigned integers, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToUIntOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): UInt?

Exception-free version of decodeToUInt

Link copied to clipboard
fun Asn1Primitive.decodeToULong(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): ULong

decodes this Asn1Primitive's content into an ULong. assertTag defaults to Asn1Element.Tag.INT, but can be overridden (for implicitly tagged unsigned longs, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToULongOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT): ULong?

Exception-free version of decodeToULong

Link copied to clipboard
fun Instant.Companion.decodeUtcTimeFromAsn1ContentBytes(input: ByteArray): Instant

Decodes an Instant from bytes assuming the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 UTC TIME

Link copied to clipboard

Encode as a four-byte array

Link copied to clipboard

Encode as an eight-byte array

Link copied to clipboard

Prepends 0x00 to this ByteArray for encoding it into a BIT STRING. No inverse function is implemented, since .drop(1) does the job.

Link copied to clipboard

Encodes this number into a ByteArray using the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 INTEGER

Encodes this boolean into a ByteArray using the same encoding as the Asn1Primitive.content property of an Asn1Primitive containing an ASN.1 BOOLEAN

Link copied to clipboard

Produces a GENERALIZED TIME as Asn1Primitive

Link copied to clipboard

Produces a UTC TIME as Asn1Primitive

Link copied to clipboard

Parses the provided input into a single Asn1Element. Consumes all Bytes and throws if more than one Asn.1 Structure was found or trailing bytes were detected

Convenience wrapper around parse, taking a ByteArray as source

Link copied to clipboard

Convenience wrapper around parseAll, taking a ByteArray as source

Tries to parse the input into a list of Asn1Elements. Consumes all Bytes and throws if an invalid ASN.1 Structure is found at any point.

Link copied to clipboard

Convenience wrapper around parseFirst, taking a ByteArray as source.

Link copied to clipboard

Decodes a single Asn1Element from this source.

Link copied to clipboard
Link copied to clipboard

Reads all parsable ASN.1 elements from this source.

Link copied to clipboard

decodes this Asn1Primitive to null (i.e. verifies the tag to be BERTags.ASN1_NULL and the content to be empty

Link copied to clipboard

Name seems odd, but this is just an exception-free version of readNull

Link copied to clipboard
fun Source.readTwosComplementInt(nBytes: Int): Int

Consumes exactly nBytes from this source and interprets it as a signed Int

Link copied to clipboard
fun Source.readTwosComplementLong(nBytes: Int): Long

Consumes exactly nBytes from this source and interprets it as a Long.

Link copied to clipboard
fun Source.readTwosComplementUInt(nBytes: Int): UInt

Consumes exactly nBytes remaining data from this source and interprets it as a UInt

Link copied to clipboard
fun Source.readTwosComplementULong(nBytes: Int): ULong

Consumes exactly nBytes from this source and interprets it as a signed ULong.

Link copied to clipboard

Encodes this number using varint encoding as used within ASN.1: groups of seven bits are encoded into a byte, while the highest bit indicates if more bytes are to come

Encodes this number using unsigned VarInt encoding as used within ASN.1: Groups of seven bits are encoded into a byte, while the highest bit indicates if more bytes are to come.

Link copied to clipboard

Encodes a signed Int to a minimum-size twos-complement byte array

Encodes a signed Long to a minimum-size twos-complement byte array

Encodes an unsigned Int to a minimum-size twos-complement byte array

Encodes an unsigned Long to a minimum-size twos-complement byte array

Link copied to clipboard

Encodes an unsigned Int to a minimum-size unsigned byte array

Encodes an unsigned Long to a minimum-size unsigned byte array

Link copied to clipboard
fun Sink.writeAsn1VarInt(number: Asn1Integer): Int
fun Sink.writeAsn1VarInt(number: UInt): Int
fun Sink.writeAsn1VarInt(number: ULong): Int

Encodes this number using varint encoding as used within ASN.1: groups of seven bits are encoded into a byte, while the highest bit indicates if more bytes are to come

Link copied to clipboard
fun Sink.writeMagnitudeLong(number: Long): Int

Encodes a positive Long to a minimum-size unsigned byte array, omitting the leading zero

Link copied to clipboard
fun Sink.writeTwosComplementLong(number: Long): Int

Writes a signed long using twos-complement encoding using the fewest bytes required

Link copied to clipboard
fun Sink.writeTwosComplementUInt(number: UInt): Int

Encodes an unsigned Int to a minimum-size twos-complement byte array

Link copied to clipboard

Encodes an unsigned Long to a minimum-size twos-complement byte array