Asn1Primitive

open class Asn1Primitive(val tag: Asn1Element.Tag, val content: ByteArray) : Asn1Element(source)

ASN.1 primitive. Hold o children, but content under tag

Inheritors

Constructors

Link copied to clipboard
constructor(tagValue: ULong, content: ByteArray)
constructor(tagValue: UByte, content: ByteArray)
constructor(tag: Asn1Element.Tag, content: ByteArray)

Properties

Link copied to clipboard

Raw data contained in this ASN.1 primitive in its encoded form. Requires decoding to interpret it

Link copied to clipboard

Lazily-evaluated DER-encoded representation of this ASN.1 element

Link copied to clipboard

Length (already properly encoded into a byte array for writing as ASN.1) of the contained data. For a primitive, this is just the size of the held bytes. For a structure, it is the sum of the number of bytes needed to encode all held child nodes.

Link copied to clipboard
open override val length: Int

Length (as a plain Int to work with it in code) of the contained data. For a primitive, this is just the size of the held bytes. For a structure, it is the sum of the number of bytes needed to encode all held child nodes.

Link copied to clipboard

Total number of bytes required to represent the ths element, when encoding to ASN.1.

Link copied to clipboard

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

Convenience function to cast this element to an Asn1EncapsulatingOctetString

Link copied to clipboard

Convenience function to cast this element to an Asn1ExplicitlyTagged

Link copied to clipboard

Convenience function to cast this element to an Asn1Primitive

Link copied to clipboard

Convenience function to cast this element to an Asn1PrimitiveOctetString

Link copied to clipboard

Convenience function to cast this element to an Asn1Sequence

Link copied to clipboard
fun asSet(): Asn1Set

Convenience function to cast this element to an Asn1Set

Link copied to clipboard

Convenience function to cast this element to an Asn1Structure

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
inline fun <T> Asn1Primitive.decodeOrNull(tag: ULong, transform: (content: ByteArray) -> T): T?

Exception-free version of decode

Link copied to clipboard
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
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
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
Link copied to clipboard
fun toDerHexString(lineLen: Int? = null): String

Convenience method to directly produce an HEX string of this element's ASN.1 representation

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Creates a new implicitly tagged ASN.1 Element from this ASN.1 Element. NOTE: The TagClass of the provided tag will be used! If you want the result to have TagClass.CONTEXT_SPECIFIC, use element withImplicitTag (tag withClass TagClass.CONTEXT_SPECIFIC)!. If a CONSTRUCTED Tag is applied to an ASN.1 Primitive, the CONSTRUCTED bit is overridden and set to zero.

Creates a new implicitly tagged ASN.1 Element from this ASN.1 Structure. If the provided template's tagClass is not set, the class of the resulting structure defaults to TagClass.CONTEXT_SPECIFIC. If a CONSTRUCTED Tag is applied to an ASN.1 Primitive, the CONSTRUCTED bit is overridden and set to zero.

infix inline fun withImplicitTag(tagValue: ULong): Asn1Element

Creates a new implicitly tagged ASN.1 Element from this ASN.1 Element. Sets the class of the resulting structure to TagClass.CONTEXT_SPECIFIC