scoop:scoop.tls:0.1.0
src/native/bindings.scoop
Selected production source · src/native/bindings.scoop
1
package scoop.tls.native3
import scoop.crypto.CryptoException4
import scoop.crypto.native.*5
import 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) }12
}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.Truncated18
case -3 -> TlsFailureKind.Verification19
case -4 -> TlsFailureKind.UnconsumedData20
case -5 -> TlsFailureKind.Configuration21
else -> TlsFailureKind.Protocol22
}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.Done28
case 1 -> TlsStepKind.WantRead29
case 2 -> TlsStepKind.WantWrite30
case 3 -> TlsStepKind.Closed31
case 4 -> TlsStepKind.WantVerification32
else -> throw IllegalStateException(Some("invalid TLS step status"))33
}, result.count)34
}36
@Extern(name = "scoop_tls_context_new") internal fun contextNew(server: Int, minimum: Int, maximum: Int, alpn: Ptr<Byte>, size: Long, store: ULong): CryptoResult37
@Extern(name = "scoop_tls_identity_new") internal fun identityNew(key: ULong, chain: Ptr<ULong>, count: Long): CryptoResult38
@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): CryptoResult40
@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): CryptoResult42
@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): NativeTlsStep44
@Extern(name = "scoop_tls_version") internal fun sessionVersion(handle: ULong): Int45
@Extern(name = "scoop_tls_alpn") internal fun sessionAlpn(handle: ULong): CryptoResult46
@Extern(name = "scoop_tls_input_capacity") internal fun inputCapacity(handle: ULong): Long47
@Extern(name = "scoop_tls_pending_output") internal fun pendingOutput(handle: ULong): Long48
@Extern(name = "scoop_tls_ciphertext") internal fun ciphertext(handle: ULong, input: Int, data: Ptr<Byte>, count: Long): CryptoResult49
@Extern(name = "scoop_tls_end_input") internal fun endInput(handle: ULong)