scoop:scoop.crypto:0.1.0
src/native/certificate.scoop
Selected production source · src/native/certificate.scoop
1
package scoop.crypto.native3
import scoop.crypto.x509.Certificate4
import scoop.crypto.x509.TrustStore5
import scoop.crypto.x509.PeerIdentity7
/**8
* Borrows the native handle of a live Certificate. The unsafe caller must keep the owner open9
* throughout native use and must not free the borrowed handle.10
*/11
@Unsafe public fun certificateHandle(value: Certificate): ULong = value.nativeHandle()12
/**13
* Borrows the native handle of a live TrustStore. The unsafe caller must keep the owner open14
* throughout native use and must not free the borrowed handle.15
*/16
@Unsafe public fun trustStoreHandle(value: TrustStore): ULong = value.nativeHandle()18
/**19
* Encodes an expected DNS or IP identity into the native certificate-verification representation.20
*/21
public fun peerIdentityData(identity: PeerIdentity): (Int, Array<Byte>) {22
when (identity) {23
case PeerIdentity.Dns(val name) -> {24
val bytes = name.toByteArray().toArray()25
if (bytes.size == 0L) throw IllegalArgumentException(Some("DNS identity must not be empty"))26
for (byte in bytes) {27
val code = byte.toUByte().toInt()28
if (code == 0 || code > 127) throw IllegalArgumentException(Some("DNS identity must be ASCII without NUL"))29
}30
return (0, bytes)31
}32
case PeerIdentity.Ip(val bytes) -> {33
if (bytes.size != 4L && bytes.size != 16L) throw IllegalArgumentException(Some("IP identity must contain 4 or 16 bytes"))34
return (1, bytes)35
}36
}37
}39
@CLayout internal struct CertificateCheck(val code: Long, val depth: Int, val error: ULong)41
@Extern(name = "scoop_crypto_certificate_import") internal fun certificateImport(pem: Int, data: Ptr<Byte>, count: Long): CryptoResult42
@Extern(name = "scoop_crypto_certificate_export") internal fun certificateExport(handle: ULong, pem: Int): CryptoResult43
@Extern(name = "scoop_crypto_certificate_text") internal fun certificateText(handle: ULong, field: Int): CryptoResult44
@Extern(name = "scoop_crypto_certificate_time") internal fun certificateTime(handle: ULong, after: Int): CryptoResult45
@Extern(name = "scoop_crypto_certificate_key") internal fun certificateKey(handle: ULong): CryptoResult46
@Extern(name = "scoop_crypto_certificate_signature") internal fun certificateSignature(handle: ULong, key: ULong): CryptoResult47
@Extern(name = "scoop_crypto_certificate_free") internal fun certificateFree(handle: ULong)48
@Extern(name = "scoop_crypto_certificate_bundle_parse") internal fun certificateBundleParse(data: Ptr<Byte>, count: Long): CryptoResult49
@Extern(name = "scoop_crypto_certificate_bundle_count") internal fun certificateBundleCount(handle: ULong): Int50
@Extern(name = "scoop_crypto_certificate_bundle_get") internal fun certificateBundleGet(handle: ULong, index: Int): CryptoResult51
@Extern(name = "scoop_crypto_certificate_bundle_free") internal fun certificateBundleFree(handle: ULong)52
@Extern(name = "scoop_crypto_certificate_names") internal fun certificateNames(handle: ULong): CryptoResult53
@Extern(name = "scoop_crypto_names_count") internal fun namesCount(handle: ULong): Int54
@Extern(name = "scoop_crypto_name_kind") internal fun nameKind(handle: ULong, index: Int): Int55
@Extern(name = "scoop_crypto_name_bytes") internal fun nameBytes(handle: ULong, index: Int): CryptoResult56
@Extern(name = "scoop_crypto_names_free") internal fun namesFree(handle: ULong)57
@Extern(name = "scoop_crypto_store_new") internal fun storeNew(): CryptoResult58
@Extern(name = "scoop_crypto_store_add") internal fun storeAdd(handle: ULong, certificate: ULong): CryptoResult59
@Extern(name = "scoop_crypto_store_free") internal fun storeFree(handle: ULong)60
@Extern(name = "scoop_crypto_certificate_verify") internal fun certificateVerify(leaf: ULong, store: ULong,61
intermediates: Ptr<ULong>, count: Long, time: Long, purpose: Int, nameKind: Int,62
name: Ptr<Byte>?, nameSize: Long): CertificateCheck63
@Extern(name = "scoop_crypto_verify_message") internal fun verifyMessage(code: Long): Ptr<Byte>