scoop:scoop.tls:0.1.0
src/native/work.scoop
Selected production source · src/native/work.scoop
1
package scoop.tls.native3
import scoop.crypto.native.CryptoResult4
import scoop.tls.*6
@CLayout7
internal struct NativeTlsWork(val pointer: Ptr<Unit>?, val error: ULong)9
@Unsafe10
internal fun workPointer(result: NativeTlsWork, operation: String): Ptr<Unit> {11
tlsValue(CryptoResult(0UL, result.error), operation)12
return result.pointer!!13
}15
/**16
* Allocates owned work for loading system trust roots. Run it, take the resulting context on17
* success, and free the work record on every exit.18
*/19
@Unsafe20
public fun prepareSystemContext(options: TlsOptions, identity: TlsIdentity?): Ptr<Unit> {21
val handle = clientHandle(0UL, options, identity)22
try {23
return workPointer(systemContextNew(handle), "prepare system TLS trust")24
}25
catch (error: Throwable) {26
contextFree(handle)27
throw error28
}29
}31
@Unsafe32
internal fun takeSystemContextHandle(work: Ptr<Unit>): ULong {33
checkedStep(systemContextResult(work), "load system TLS trust")34
return systemContextTake(work)35
}37
/**38
* Takes the client context from completed system-trust work, reporting any recorded failure. The39
* work record must still be released afterward.40
*/41
@Unsafe42
public fun takeSystemContext(work: Ptr<Unit>): TlsClientContext =43
TlsClientContext.takeOwnership(takeSystemContextHandle(work))45
@Extern(name = "scoop_tls_system_context_new")46
private fun systemContextNew(context: ULong): NativeTlsWork48
@Extern(name = "scoop_tls_system_context_result")49
private fun systemContextResult(work: Ptr<Unit>): NativeTlsStep51
@Extern(name = "scoop_tls_system_context_take")52
private fun systemContextTake(work: Ptr<Unit>): ULong54
/**55
* Runs prepared system-trust loading work synchronously. The work pointer must remain valid until56
* execution finishes.57
*/58
@Extern(name = "scoop_tls_system_context_run")59
public fun runSystemContext(work: Ptr<Unit>)61
/**62
* Releases an owned system-trust work record and any result not already taken. Call once after its63
* execution has stopped.64
*/65
@Extern(name = "scoop_tls_system_context_free")66
public fun freeSystemContext(work: Ptr<Unit>)68
@Extern(name = "scoop_tls_verification_take")69
internal fun takeVerification(handle: ULong): NativeTlsWork71
@Extern(name = "scoop_tls_verification_complete")72
internal fun completeVerification(handle: ULong, work: Ptr<Unit>): CryptoResult74
/**75
* Runs an owned TLS certificate-verification work record synchronously.76
*/77
@Extern(name = "scoop_tls_verification_run")78
public fun runVerification(work: Ptr<Unit>)80
/**81
* Releases a verification work record after execution and result delivery have finished.82
*/83
@Extern(name = "scoop_tls_verification_free")84
public fun freeVerification(work: Ptr<Unit>)