Scoop API

scoop:scoop.tls:0.1.0

src/native/bindings.scoop

Selected production source · src/native/bindings.scoop

1package scoop.tls.native
3import scoop.crypto.CryptoException
4import scoop.crypto.native.*
5import scoop.tls.*
7@CLayout internal struct NativeTlsStep(val status: Int, val systemError: Int, val count: Long, val verifyCode: Long, val error: ULong)
9@Unsafe internal fun tlsValue(result: CryptoResult, operation: String): ULong {
10 try { return cryptoValue(result, operation) }
11 catch (error: CryptoException) { throw TlsException(operation, TlsFailureKind.Configuration, error.code, 0L, 0, error.detail) }
14@Unsafe internal fun checkedStep(result: NativeTlsStep, operation: String): TlsStep {
15 if (result.error != 0UL) {
16 val kind = when (result.status) {
17 case -2 -> TlsFailureKind.Truncated
18 case -3 -> TlsFailureKind.Verification
19 case -4 -> TlsFailureKind.UnconsumedData
20 case -5 -> TlsFailureKind.Configuration
21 else -> TlsFailureKind.Protocol
22 }
23 try { cryptoValue(CryptoResult(0UL, result.error), operation) }
24 catch (error: CryptoException) { throw TlsException(operation, kind, error.code, result.verifyCode, result.systemError, error.detail) }
25 }
26 return TlsStep(when (result.status) {
27 case 0 -> TlsStepKind.Done
28 case 1 -> TlsStepKind.WantRead
29 case 2 -> TlsStepKind.WantWrite
30 case 3 -> TlsStepKind.Closed
31 case 4 -> TlsStepKind.WantVerification
32 else -> throw IllegalStateException(Some("invalid TLS step status"))
33 }, result.count)
36@Extern(name = "scoop_tls_context_new") internal fun contextNew(server: Int, minimum: Int, maximum: Int, alpn: Ptr<Byte>, size: Long, store: ULong): CryptoResult
37@Extern(name = "scoop_tls_identity_new") internal fun identityNew(key: ULong, chain: Ptr<ULong>, count: Long): CryptoResult
38@Extern(name = "scoop_tls_identity_free") internal fun identityFree(handle: ULong)
39@Extern(name = "scoop_tls_context_identity") internal fun contextIdentity(handle: ULong, identity: ULong): CryptoResult
40@Extern(name = "scoop_tls_context_free") internal fun contextFree(handle: ULong)
41@Extern(name = "scoop_tls_session_new") internal fun sessionNew(context: ULong, server: Int, nameKind: Int, name: Ptr<Byte>?, size: Long): CryptoResult
42@Extern(name = "scoop_tls_session_free") internal fun sessionFree(handle: ULong)
43@Extern(name = "scoop_tls_step") internal fun sessionStep(handle: ULong, operation: Int, data: Ptr<Byte>?, count: Long): NativeTlsStep
44@Extern(name = "scoop_tls_version") internal fun sessionVersion(handle: ULong): Int
45@Extern(name = "scoop_tls_alpn") internal fun sessionAlpn(handle: ULong): CryptoResult
46@Extern(name = "scoop_tls_input_capacity") internal fun inputCapacity(handle: ULong): Long
47@Extern(name = "scoop_tls_pending_output") internal fun pendingOutput(handle: ULong): Long
48@Extern(name = "scoop_tls_ciphertext") internal fun ciphertext(handle: ULong, input: Int, data: Ptr<Byte>, count: Long): CryptoResult
49@Extern(name = "scoop_tls_end_input") internal fun endInput(handle: ULong)