Asn1Primitive

ASN.1 primitive. Holds no children, but content under tag

Inheritors

Constructors

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

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Length (as a plain Int to work with it in code) of the contained data. Guarded: throws Asn1Exception if contentLengthLong exceeds Int.MAX_VALUE (a >2 GiB aggregate) rather than silently overflowing. For such elements use contentLengthLong.

Link copied to clipboard
open override val contentLengthLong: Long

Length of the contained data as a Long. This is the overflow-safe source of truth; for a primitive it is the size of the held bytes, for a structure the sum of the encoded sizes of all child nodes.

Link copied to clipboard
open override val derEncoded: ByteArray

DER-encoded representation of this ASN.1 element.

Link copied to clipboard
Link copied to clipboard

Total number of bytes required to represent this element when encoding to ASN.1. Guarded: throws Asn1Exception if overallLengthLong exceeds Int.MAX_VALUE. For such elements use overallLengthLong.

Link copied to clipboard

Total number of bytes required to represent this element when encoding to ASN.1, as a Long. Computed arithmetically from the (sentinel-cached) contentLengthLong — no lazy, no materialized length array — so the length post-order (Asn1Structure.contentLengthLong) can sum children without per-node lock/allocation.

Link copied to clipboard

Functions

Link copied to clipboard
fun Asn1Primitive.asAsn1BitString(assertTag: Asn1Element.Tag = Asn1Element.Tag.BIT_STRING): Asn1BitString

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

Link copied to clipboard
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 Asn1OctetString

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 Asn1Sequence

Link copied to clipboard

Convenience function to cast this element to an Asn1SequenceOf

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 Asn1SetOf

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
fun Asn1Primitive.decodeToAsn1Integer(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT, lenient: Boolean = false): Asn1Integer

Decode the Asn1Primitive as an Asn1Integer

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

Exception-free version of decodeToAsn1Integer

Link copied to clipboard
fun Asn1Primitive.decodeToAsn1Real(assertTag: Asn1Element.Tag = Asn1Element.Tag.REAL, lenient: Boolean = false): Asn1Real

Decode the Asn1Primitive as an Asn1Real

Link copied to clipboard
inline fun Asn1Primitive.decodeToAsn1RealOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.REAL, lenient: Boolean = false): Asn1Real?

Exception-free version of decodeToAsn1Real

Link copied to clipboard
inline fun Asn1Primitive.decodeToBmpString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_BMP): Asn1String.BMP

decodes this Asn1Primitive's content into a Asn1String.BMP. assertTag defaults to Asn1Element.Tag.STRING_BMP, but can be overridden (for implicitly tagged strings, for example)

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
fun Asn1Primitive.decodeToDouble(assertTag: Asn1Element.Tag = Asn1Element.Tag.REAL, lenient: Boolean = false): Double

Decode the Asn1Primitive as a Double. Beware of possible loss of precision!

Link copied to clipboard
inline fun Asn1Primitive.decodeToDoubleOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.REAL, lenient: Boolean = false): Double?

Exception-free version of decodeToDouble. Beware of possible loss of precision!

Link copied to clipboard
inline fun <E : Enum<E>> Asn1Primitive.decodeToEnum(assertTag: Asn1Element.Tag = Asn1Element.Tag.ENUM, lenient: Boolean = false): E

decodes this Asn1Primitive's content into an enum Entry based on the decoded ordinal. assertTag defaults to Asn1Element.Tag.ENUM, but can be overridden (for implicitly tagged enums, for example).

Link copied to clipboard
fun Asn1Primitive.decodeToEnumOrdinal(assertTag: Asn1Element.Tag = Asn1Element.Tag.ENUM, lenient: Boolean = false): Long

decodes this Asn1Primitive's content into an enum ordinal represented as Long. assertTag defaults to Asn1Element.Tag.ENUM, but can be overridden (for implicitly tagged enums, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToEnumOrdinalOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.ENUM, lenient: Boolean = false): Long?

Exception-free version of decodeToEnumOrdinal

Link copied to clipboard
inline fun <E : Enum<E>> Asn1Primitive.decodeToEnumOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.ENUM, lenient: Boolean = false): E?

Exception-free version of decodeToEnum

Link copied to clipboard
inline fun Asn1Primitive.decodeToFloat(assertTag: Asn1Element.Tag = Asn1Element.Tag.REAL, lenient: Boolean = false): Float

Decode the Asn1Primitive as a Float. Beware of probable loss of precision!

Link copied to clipboard
inline fun Asn1Primitive.decodeToFloatOrNull(assertTag: Asn1Element.Tag = Asn1Element.Tag.REAL, lenient: Boolean = false): Float?

Exception-free version of decodeToFloat. Beware of probable loss of precision!

Link copied to clipboard
inline fun Asn1Primitive.decodeToGeneralString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_GENERAL): Asn1String.General

decodes this Asn1Primitive's content into a Asn1String.General. assertTag defaults to Asn1Element.Tag.STRING_GENERAL, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToGraphicString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_GRAPHIC): Asn1String.Graphic

decodes this Asn1Primitive's content into a Asn1String.Graphic. assertTag defaults to Asn1Element.Tag.STRING_GRAPHIC, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToIa5String(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_IA5): Asn1String.IA5

decodes this Asn1Primitive's content into a Asn1String.IA5. assertTag defaults to Asn1Element.Tag.STRING_IA5, but can be overridden (for implicitly tagged strings, for example)

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
Link copied to clipboard
fun Asn1Primitive.decodeToInt(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT, lenient: Boolean = false): 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, lenient: Boolean = false): Int?

Exception-free version of decodeToInt

Link copied to clipboard
fun Asn1Primitive.decodeToLong(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT, lenient: Boolean = false): 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, lenient: Boolean = false): Long?

Exception-free version of decodeToLong

Link copied to clipboard
inline fun Asn1Primitive.decodeToNumericString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_NUMERIC): Asn1String.Numeric

decodes this Asn1Primitive's content into a Asn1String.Numeric. assertTag defaults to Asn1Element.Tag.STRING_NUMERIC, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToPrintableString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_PRINTABLE): Asn1String.Printable

decodes this Asn1Primitive's content into a Asn1String.Printable. assertTag defaults to Asn1Element.Tag.STRING_PRINTABLE, but can be overridden (for implicitly tagged strings, for example)

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
inline fun Asn1Primitive.decodeToTeletextString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_T61): Asn1String.Teletex

decodes this Asn1Primitive's content into a Asn1String.Teletex. assertTag defaults to Asn1Element.Tag.STRING_T61, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
fun Asn1Primitive.decodeToUInt(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT, lenient: Boolean = false): 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, lenient: Boolean = false): UInt?

Exception-free version of decodeToUInt

Link copied to clipboard
fun Asn1Primitive.decodeToULong(assertTag: Asn1Element.Tag = Asn1Element.Tag.INT, lenient: Boolean = false): 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, lenient: Boolean = false): ULong?

Exception-free version of decodeToULong

Link copied to clipboard
inline fun Asn1Primitive.decodeToUniversalString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_UNIVERSAL): Asn1String.Universal

decodes this Asn1Primitive's content into a Asn1String.Universal. assertTag defaults to Asn1Element.Tag.STRING_UNIVERSAL, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToUnrestrictedString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_UNRESTRICTED): Asn1String.Unrestricted

decodes this Asn1Primitive's content into a Asn1String.Unrestricted. assertTag defaults to Asn1Element.Tag.STRING_UNRESTRICTED, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToUtf8String(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_UTF8): Asn1String.UTF8

decodes this Asn1Primitive's content into a Asn1String.UTF8. assertTag defaults to Asn1Element.Tag.STRING_UTF8, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToVideotexString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_VIDEOTEX): Asn1String.Videotex

decodes this Asn1Primitive's content into a Asn1String.Videotex. assertTag defaults to Asn1Element.Tag.STRING_VIDEOTEX, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
inline fun Asn1Primitive.decodeToVisibleString(assertTag: Asn1Element.Tag = Asn1Element.Tag.STRING_VISIBLE): Asn1String.Visible

decodes this Asn1Primitive's content into a Asn1String.Visible. assertTag defaults to Asn1Element.Tag.STRING_VISIBLE, but can be overridden (for implicitly tagged strings, for example)

Link copied to clipboard
fun encodeTo(sink: Sink)
Link copied to clipboard
operator override fun equals(other: Any?): Boolean
Link copied to clipboard
override fun hashCode(): Int
Link copied to clipboard
fun prettyPrint(limit: Long = MAX_RENDER_CHARS): String

Verbose, indented human-readable tree, truncated at limit characters with a marker (see renderTo).

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 renderTo(out: Sink, pretty: Boolean, limit: Long)

Stack-safe renderer that writes this element's compact (pretty = false) or indented (pretty = true) string form as UTF-8 into out, stopping after limit characters (appending a truncation marker). Expressed with DeepRecursiveFunction so deep nesting cannot overflow the call stack; reuses the per-node prettyPrintHeader/prettyPrintTrailer/contentToString so output is unchanged for ordinary elements.

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

fun toString(limit: Long): String

Compact single-line rendering, truncated at limit characters with a marker (see renderTo).

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