Util

object Util

Utility functions.

Functions

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun calcEMacKeyForReader(authenticationPublicKey: PublicKey, ephemeralReaderPrivateKey: PrivateKey, encodedSessionTranscript: ByteArray): SecretKey
Link copied to clipboard
Link copied to clipboard
fun cborBuildCoseKey(key: PublicKey, curve: EcCurve): DataItem
Link copied to clipboard
fun cborBuildDateTime(timestamp: Timestamp): DataItem

Returns #6.0(tstr) where tstr is the ISO 8601 encoding of the given point in time. Only supports UTC times.

Link copied to clipboard
fun cborBuildTaggedByteString(encodedCbor: ByteArray): DataItem

Returns #6.24(bstr) of the given already encoded CBOR

Link copied to clipboard
fun cborDecode(encodedBytes: ByteArray): DataItem
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun cborEncode(dataItem: DataItem): ByteArray
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Extracts the first CBOR data item from a stream of bytes.

Link copied to clipboard
fun cborExtractTaggedAndEncodedCbor(item: DataItem): DataItem

For a #6.24(bstr), extracts the bytes and decodes it and returns the decoded CBOR as a DataItem.

Link copied to clipboard
fun cborExtractTaggedCbor(encodedTaggedBytestring: ByteArray): ByteArray

For a #6.24(bstr), extracts the bytes.

Link copied to clipboard

Helper to determine the length of a single encoded CBOR data item.

Link copied to clipboard
fun cborMapExtract(map: DataItem, key: String): DataItem
Link copied to clipboard
fun cborMapExtractArray(map: DataItem, key: Long): List<DataItem>
fun cborMapExtractArray(map: DataItem, key: String): List<DataItem>
Link copied to clipboard
fun cborMapExtractBoolean(map: DataItem, key: Long): Boolean
fun cborMapExtractBoolean(map: DataItem, key: String): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun cborMapExtractMap(map: DataItem, key: String): DataItem
Link copied to clipboard
Link copied to clipboard
fun cborMapExtractNumber(map: DataItem, key: Long): Long
fun cborMapExtractNumber(map: DataItem, key: String): Long
Link copied to clipboard
fun cborMapExtractString(map: DataItem, key: Long): String
fun cborMapExtractString(map: DataItem, key: String): String
Link copied to clipboard
fun cborMapHasKey(map: DataItem, key: Long): Boolean
fun cborMapHasKey(map: DataItem, key: String): Boolean
Link copied to clipboard
fun cborPrettyPrint(dataItem: DataItem): String
Link copied to clipboard
fun checkedLongValue(item: DataItem): Long

Accepts a DataItem, attempts to cast it to a Number, then returns the value Throws IllegalArgumentException if the DataItem is not a Number. This method also checks bounds, and if the given data item is too large to fit in a long, it throws ArithmeticException.

Link copied to clipboard
fun checkedStringValue(item: DataItem): String

Accepts a DataItem, attempts to cast it to a UnicodeString, then returns the value. Throws IllegalArgumentException if the DataItem is not a UnicodeString.

Link copied to clipboard
fun computeHkdf(macAlgorithm: String, ikm: ByteArray, salt: ByteArray?, info: ByteArray?, size: Int): ByteArray

Computes an HKDF.

Link copied to clipboard
fun coseKeyDecode(coseKey: DataItem): PublicKey
Link copied to clipboard
fun coseKeyGetCurve(coseKey: DataItem): EcCurve
Link copied to clipboard
fun coseMac0(key: SecretKey, data: ByteArray?, detachedContent: ByteArray?): DataItem
Link copied to clipboard
fun coseMac0GetTag(coseMac0: DataItem): ByteArray
Link copied to clipboard
fun coseSign1CheckSignature(coseSign1: DataItem, detachedContent: ByteArray?, publicKey: PublicKey): Boolean

Currently only ECDSA signatures are supported.

Link copied to clipboard
fun coseSign1GetData(coseSign1: DataItem): ByteArray

Returns the empty byte-array if no data is included in the structure.

Link copied to clipboard

Returns the empty collection if no x5chain is included in the structure.

Link copied to clipboard
fun coseSign1Sign(s: Signature, data: ByteArray?, detachedContent: ByteArray?, certificateChain: Collection<X509Certificate>?): DataItem

fun coseSign1Sign(key: PrivateKey, algorithm: String, data: ByteArray?, additionalData: ByteArray?, certificateChain: Collection<X509Certificate>?): DataItem

Note: this uses the default JCA provider which may not support a lot of curves, for example it doesn't support Brainpool curves. If you need to use such curves, use .coseSign1Sign instead with a Signature created using a provider that does have support.

Link copied to clipboard
fun createItemsRequest(entriesToRequest: Map<String?, Collection<String?>>, docType: String?): ByteArray

Helper function to create a CBOR data for requesting data items. The IntentToRetain value will be set to false for all elements.

Link copied to clipboard
Link copied to clipboard
fun fromHex(stringWithHex: String): ByteArray
Link copied to clipboard
fun getDeviceRetrievalMethodType(encodeDeviceRetrievalMethod: ByteArray): Long
Link copied to clipboard

Brute-force but good enough since users will only pass relatively small amounts of data.

Link copied to clipboard

Clears elementValue in IssuerSignedItemBytes CBOR.

Link copied to clipboard
fun issuerSignedItemSetValue(encodedIssuerSignedItem: ByteArray, encodedElementValue: ByteArray): ByteArray

Sets elementValue in IssuerSignedItem CBOR.

Link copied to clipboard

Version comparison method for mdoc versions.

Link copied to clipboard
fun readBytes(inputStream: InputStream, numBytes: Int): ByteBuffer?
Link copied to clipboard
fun replaceLine(text: String, lineNumber: Int, replacementLine: String): String
Link copied to clipboard
fun sec1EncodeFieldElementAsOctetString(octetStringSize: Int, fieldValue: BigInteger?): ByteArray
Link copied to clipboard
fun signPublicKeyWithPrivateKey(keyToSignAlias: String, keyToSignWithAlias: String): X509Certificate
Link copied to clipboard
Link copied to clipboard
fun toHex(bytes: ByteArray, from: Int, to: Int): String
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Helper function to check if a given certificate chain is valid.