Package-level declarations

Types

Link copied to clipboard

ASN.1 BIT STRING

Link copied to clipboard

ASN1 structure (i.e. containing child nodes) with custom tag

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
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

Generic serializer for ASN.1 tree model types.

Link copied to clipboard
Link copied to clipboard
interface Asn1Encodable<out A : Asn1Element>

Interface providing methods to encode to ASN.1

Link copied to clipboard
open class Asn1Exception(message: String?, cause: Throwable?) : Throwable
Link copied to clipboard

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

Link copied to clipboard

A very simple implementation of an ASN.1 variable-length integer. It is only good for reading from and writing to ASN.1 structures. It is not a BigInt, nor does it define any operations. It has a sign though, and supports twosComplement representation and converting fromTwosComplement. Hence, it directly interoperates with Kotlin MP BigNum and the JVM BigInteger.

Link copied to clipboard

String serializer for Asn1Integer.

Link copied to clipboard
sealed interface Asn1OctetString

Interface describing an ASN.1 OCTET STRING.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open class Asn1Primitive(tag: Asn1Element.Tag, val content: ByteArray) : Asn1Element

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

Link copied to clipboard

ASN.1 OCTET STRING 0x04 (BERTags.OCTET_STRING) containing arbitrary bytes

Link copied to clipboard
@Serializable(with = Asn1Real.Companion::class)
sealed interface Asn1Real : Asn1Encodable<Asn1Primitive>

ASN.1 REAL number. Mind possible loss of precision compared to Kotlin's built-in types. This type is irrelevant for PKI applications, but required for generic ASN.1 serialization

Link copied to clipboard
object Asn1RealStringSerializer : KSerializer<Asn1Real>

String serializer for Asn1Real.

Link copied to clipboard
Link copied to clipboard
open class Asn1Set : Asn1Structure

ASN.1 SET 0x31 (BERTags.SET OR BERTags.CONSTRUCTED)

Link copied to clipboard

ASN.1 SET OF 0x31 (BERTags.SET OR BERTags.CONSTRUCTED)

Link copied to clipboard

ASN.1 String class used as wrapper do discriminate between different ASN.1 string types By default, the string value is decoded using UTF-8. If a different charset or custom decoding is needed, the rawValue property can be used directly.

Link copied to clipboard
class Asn1StructuralException(message: String, cause: Throwable? = null) : Asn1Exception
Link copied to clipboard

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

Link copied to clipboard
class Asn1TagMismatchException(val expected: Asn1Element.Tag, val actual: Asn1Element.Tag, detailedMessage: String? = null) : Asn1Exception
Link copied to clipboard
@Serializable(with = Asn1Time.Companion::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
object BERTags
Link copied to clipboard
@Serializable(with = BitSetSerializer::class)
class BitSet : Iterable<Boolean>

Pure Kotlin Bit Set created by throwing a bunch of extension functions at a MutableList<Byte>. As a mental model: this BitSet grows from left to right, just like writing a text.

Link copied to clipboard
object BitSetSerializer : KSerializer<BitSet>

String serializer for BitSet used for interoperability with non-DER serialization formats.

Link copied to clipboard
Link copied to clipboard
interface Identifiable

Adds oid to the implementing class

Link copied to clipboard
class ImplementationError(message: String? = null) : Throwable
Link copied to clipboard
annotation class InternalAwesn1Api
Link copied to clipboard

Holds known OIDs and their descriptions. If the oids module is part of your classpath, call KnownOIDs.describeAll() to add descriptions for all known OID constants shipped with the module.

Link copied to clipboard

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

String-based serializer for ObjectIdentifier.

Link copied to clipboard
data class PemBlock(val label: String, val headers: List<PemHeader> = emptyList(), val payload: ByteArray)
Link copied to clipboard
interface PemDecodable<out T>
Link copied to clipboard
interface PemEncodable
Link copied to clipboard
data class PemHeader(val name: String, val value: String)
Link copied to clipboard
Link copied to clipboard
sealed interface TagProperty

Properties

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

ASN.1 NULL as constant

Functions

Link copied to clipboard
Link copied to clipboard
inline fun <T : Asn1Element> T.assertTag(tag: Asn1Element.Tag): T

asserts that this element's tag matches tag.

inline fun <T : Asn1Element> T.assertTag(tagNumber: ULong): T

Asserts only the tag number, but neither class, nor CONSTRUCTED bit.

Link copied to clipboard
inline fun <T> catchingUnwrapped(block: () -> T): Result<T>

Non-fatal-only-catching version of stdlib's runCatching, returning a Result -- Re-throws any fatal exceptions, such as OutOfMemoryError. Re-implements Arrow's nonFatalOrThrow logic to avoid a dependency on Arrow for a single function.

Link copied to clipboard
inline fun <T, R> T.catchingUnwrapped(block: T.() -> R): Result<R>
Link copied to clipboard
fun BitSet.clear(index: Int)
fun BitSet.clear(longRange: LongRange)
fun BitSet.clear(fromIndex: Long, toIndex: Long)

fun BitSet.clear(index: Long)

shorthand for set(index, false)

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun <A : Asn1Element, T : Asn1Encodable<A>> Asn1Decodable<A, T>.decodeFromTlvOrNull(src: A, assertTag: Asn1Element.Tag? = null): T?

Exception-free version of Asn1Decodable.decodeFromTlv

Link copied to clipboard
inline fun <R> Asn1Structure.decodeRethrowing(requireFullConsumption: Boolean = true, decoder: Asn1Structure.Iterator.() -> R): R

Decodes this ASN.1 structure using the provided decoder lambda, rethrowing any caught exception as an Asn1Exception. This is a wrapper around Asn1Structure.decodeAs that ensures exceptions thrown during decoding are consistently rethrown as Asn1Exception, using the runRethrowing utility.

Link copied to clipboard
@JvmName(name = "encodeAllPemBlocksToPemStatic")
fun encodeAllToPem(src: Iterable<PemBlock>): String
Link copied to clipboard
@JvmName(name = "encodeAllPemBlocksToPem")
fun Iterable<PemBlock>.encodeAllToPem(): String
@JvmName(name = "encodeAllPemEncodablesToPem")
fun Iterable<PemEncodable>.encodeAllToPem(): String
Link copied to clipboard
@JvmName(name = "encodeToPemBlockStatic")
fun encodeToPem(src: PemBlock): String
Link copied to clipboard
@JvmName(name = "encodePemBlockToPem")
fun PemBlock.encodeToPem(): String
Link copied to clipboard
Link copied to clipboard

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

Link copied to clipboard
fun BitSet.flip(index: Int)
fun BitSet.flip(index: Long)
fun BitSet.flip(indexes: LongRange)
fun BitSet.flip(fromIndex: Long, toIndex: Long)
Link copied to clipboard
fun ERROR CLASS: Symbol not found for Uuid.Companion.fromBigintOrNull(bigInteger: BigInteger): ERROR CLASS: Symbol not found for Uuid??

Tries to convert a BigInteger to a UUID. Only guaranteed to work with BigIntegers that contain the unsigned (positive) integer representation of a UUID, chances are high, though, that it works with random positive BigIntegers between 16 and 14 bytes long.

Link copied to clipboard
operator fun BitSet.get(index: Int): Boolean
Link copied to clipboard
Link copied to clipboard

Returns a binary representation of this byte array's memory layout Bytes are separated by a single space. An empty byte array results in an empty string.

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

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

Link copied to clipboard
actual inline fun Throwable.safeThrow(): Throwable
expect inline fun Throwable.safeThrow(): Throwable
actual inline fun Throwable.safeThrow(): Throwable
Link copied to clipboard
fun BitSet.set(index: Int)
fun BitSet.set(indexes: LongRange)
operator fun BitSet.set(index: Int, value: Boolean)
fun BitSet.set(fromIndex: Long, toIndex: Long)

fun BitSet.set(index: Long)

shorthand for set(index, true)

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

Link copied to clipboard
fun ERROR CLASS: Symbol not found for Uuid.toBigInteger(): BigInteger

Converts this UUID to a BigInteger representation

Link copied to clipboard

copies this byteArray into a BitSet

Link copied to clipboard

Returns all bits as they are accessible by the global bit index (i.e. after wrapping this ByteArray into a BitSet)

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun <E : Throwable, R> Result<R>.wrapAs(a: (Throwable) -> E): Result<R>
Link copied to clipboard

Directly moves the byte array to a buffer without copying. Thus, it keeps bytes managed by a Buffer accessible. The bytes may be overwritten through the Buffer or even recycled to be used by another buffer. Therefore, operating on these bytes after wrapping leads to undefined behaviour.

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