Scoop API

scoop:scoop.crypto:0.1.0

src/native/certificate.scoop

Selected production source · src/native/certificate.scoop

1package scoop.crypto.native
3import scoop.crypto.x509.Certificate
4import scoop.crypto.x509.TrustStore
5import scoop.crypto.x509.PeerIdentity
7/**
8 * Borrows the native handle of a live Certificate. The unsafe caller must keep the owner open
9 * 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 open
14 * 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 */
21public 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 }
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): CryptoResult
42@Extern(name = "scoop_crypto_certificate_export") internal fun certificateExport(handle: ULong, pem: Int): CryptoResult
43@Extern(name = "scoop_crypto_certificate_text") internal fun certificateText(handle: ULong, field: Int): CryptoResult
44@Extern(name = "scoop_crypto_certificate_time") internal fun certificateTime(handle: ULong, after: Int): CryptoResult
45@Extern(name = "scoop_crypto_certificate_key") internal fun certificateKey(handle: ULong): CryptoResult
46@Extern(name = "scoop_crypto_certificate_signature") internal fun certificateSignature(handle: ULong, key: ULong): CryptoResult
47@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): CryptoResult
49@Extern(name = "scoop_crypto_certificate_bundle_count") internal fun certificateBundleCount(handle: ULong): Int
50@Extern(name = "scoop_crypto_certificate_bundle_get") internal fun certificateBundleGet(handle: ULong, index: Int): CryptoResult
51@Extern(name = "scoop_crypto_certificate_bundle_free") internal fun certificateBundleFree(handle: ULong)
52@Extern(name = "scoop_crypto_certificate_names") internal fun certificateNames(handle: ULong): CryptoResult
53@Extern(name = "scoop_crypto_names_count") internal fun namesCount(handle: ULong): Int
54@Extern(name = "scoop_crypto_name_kind") internal fun nameKind(handle: ULong, index: Int): Int
55@Extern(name = "scoop_crypto_name_bytes") internal fun nameBytes(handle: ULong, index: Int): CryptoResult
56@Extern(name = "scoop_crypto_names_free") internal fun namesFree(handle: ULong)
57@Extern(name = "scoop_crypto_store_new") internal fun storeNew(): CryptoResult
58@Extern(name = "scoop_crypto_store_add") internal fun storeAdd(handle: ULong, certificate: ULong): CryptoResult
59@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): CertificateCheck
63@Extern(name = "scoop_crypto_verify_message") internal fun verifyMessage(code: Long): Ptr<Byte>