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

ASN.1 BIT STRING

Link copied to clipboard

Interface providing convenience methods to decode from ASN.1. Especially useful when companion objects of classes implementing Asn1Encodable implement it.

Link copied to clipboard
@Serializable(with = Asn1EncodableSerializer::class)
sealed class Asn1Element

Base ASN.1 data class. Can either be a primitive (holding a value), or a structure (holding other ASN.1 elements)

Link copied to clipboard

Interface providing methods to encode to ASN.1

Link copied to clipboard
object Asn1EncodableSerializer : KSerializer<Asn1Element>
Link copied to clipboard
open class Asn1Exception(message: String?, cause: Throwable?) : Throwable
Link copied to clipboard

Interface describing an ASN.1 OCTET STRING. This is really more of a crutch, since an octet string is either an

Link copied to clipboard
Link copied to clipboard
open class Asn1Primitive(tag: UByte, content: ByteArray) : Asn1Element

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

Link copied to clipboard

ASN.1 OCTET STRING 0x04 (BERTags.OCTET_STRING) containing data, which does not decode to an Asn1Element

Link copied to clipboard

ASN.1 SEQUENCE 0x30 (DERTags.DER_SEQUENCE)

Link copied to clipboard
open class Asn1Set : Asn1Structure

ASN.1 SET 0x31 (DERTags.DER_SET)

Link copied to clipboard

ASN.1 SET OF 0x31 (DERTags.DER_SET)

Link copied to clipboard
@Serializable
sealed class Asn1String : Asn1Encodable<Asn1Primitive>

ASN.! String class used as wrapper do discriminate between different ASN.1 string types

Link copied to clipboard
Link copied to clipboard
sealed class Asn1Structure : Asn1Element

ASN.1 structure. Contains no data itself, but holds zero or more children

Link copied to clipboard

Explicit ASN.1 Tag. Can contain any number of children

Link copied to clipboard
class Asn1TagMismatchException(val expected: UByte, val actual: UByte, detailedMessage: String? = null) : Asn1Exception
Link copied to clipboard
@Serializable(with = CertTimeStampSerializer::class)
class Asn1Time(instant: Instant, formatOverride: Asn1Time.Format? = null) : Asn1Encodable<Asn1Primitive>

ASN.1 TIME (required since GENERALIZED TIME and UTC TIME exist)

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:

Link copied to clipboard
object BERTags
Link copied to clipboard
object CertTimeStampSerializer : KSerializer<Asn1Time>
Link copied to clipboard
object DERTags
Link copied to clipboard
interface Identifiable

Adds oid to the implementing class

Link copied to clipboard
object KnownOIDs
Link copied to clipboard
@Serializable(with = ObjectIdSerializer::class)
class ObjectIdentifier constructor(val nodes: UInt) : Asn1Encodable<Asn1Primitive>

ASN.1 OBJECT IDENTIFIER featuring the most cursed encoding of numbers known to man, which probably surfaced due to an ungodly combination of madness, cruelty and a twisted sense of humour. Courtesy of what were most probably tormented souls to begin with.

Link copied to clipboard
object ObjectIdSerializer : KSerializer<ObjectIdentifier>
Link copied to clipboard
data class TLV(val tag: UByte, val content: ByteArray)

Functions

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

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

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

Exception-free version of decode

Link copied to clipboard

Encode as a four-byte array

Link copied to clipboard

Encode as an eight-byte array

Link copied to clipboard

Produces a GENERALIZED TIME as Asn1Primitive

Link copied to clipboard

Produces a UTC TIME as Asn1Primitive

Link copied to clipboard

Prepends 0x00 to this ByteArray for encoding it into a BIT STRING. Useful for implicit tagging

Link copied to clipboard

Encodes a signed Long correctly to a compact byte array

Link copied to clipboard
fun BigInteger.encodeToTlv(): Asn1Primitive

Produces an INTEGER as Asn1Primitive

Produces a BOOLEAN as Asn1Primitive

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Drops or adds zero bytes at the start until the size is reached

inline fun ByteArray.ensureSize(size: UInt): ByteArray
Link copied to clipboard

Parses the provides input into a single Asn1Element

Link copied to clipboard
fun Asn1Primitive.readBigInteger(): BigInteger

Decode the Asn1Primitive as a BigInteger

Link copied to clipboard
inline fun Asn1Primitive.readBigIntegerOrNull(): BigInteger?

Exception-free version of readBigInteger

Link copied to clipboard

decodes this Asn1Primitive's content into an ByteArray, assuming it was encoded as BIT STRING

Link copied to clipboard
Link copied to clipboard

decodes this Asn1Primitive's content into an Boolean

Link copied to clipboard
fun Asn1Primitive.readInstant(): Instant

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 readInstant

Link copied to clipboard

decodes this Asn1Primitive's content into an Int

Link copied to clipboard

Exception-free version of readInt

Link copied to clipboard

decodes this Asn1Primitive's content into a Long

Link copied to clipboard

Exception-free version of readLong

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

decodes this Asn1Primitive's content into an Asn1String

Link copied to clipboard

Exception-free version of readString

Link copied to clipboard
inline fun <R> runRethrowing(block: () -> R): R

Runs block inside catching and encapsulates any thrown exception in an Asn1Exception unless it already is one

Link copied to clipboard

Returns this Asn1Tagged children, if its tag matches tag

Link copied to clipboard

Exception-free version of verifyTag