Scoop API

scoop:scoop.tls:0.1.0

src/native/work.scoop

Selected production source · src/native/work.scoop

1package scoop.tls.native
3import scoop.crypto.native.CryptoResult
4import scoop.tls.*
6@CLayout
7internal struct NativeTlsWork(val pointer: Ptr<Unit>?, val error: ULong)
9@Unsafe
10internal fun workPointer(result: NativeTlsWork, operation: String): Ptr<Unit> {
11 tlsValue(CryptoResult(0UL, result.error), operation)
12 return result.pointer!!
15/**
16 * Allocates owned work for loading system trust roots. Run it, take the resulting context on
17 * success, and free the work record on every exit.
18 */
19@Unsafe
20public 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 error
28 }
31@Unsafe
32internal fun takeSystemContextHandle(work: Ptr<Unit>): ULong {
33 checkedStep(systemContextResult(work), "load system TLS trust")
34 return systemContextTake(work)
37/**
38 * Takes the client context from completed system-trust work, reporting any recorded failure. The
39 * work record must still be released afterward.
40 */
41@Unsafe
42public fun takeSystemContext(work: Ptr<Unit>): TlsClientContext =
43 TlsClientContext.takeOwnership(takeSystemContextHandle(work))
45@Extern(name = "scoop_tls_system_context_new")
46private fun systemContextNew(context: ULong): NativeTlsWork
48@Extern(name = "scoop_tls_system_context_result")
49private fun systemContextResult(work: Ptr<Unit>): NativeTlsStep
51@Extern(name = "scoop_tls_system_context_take")
52private fun systemContextTake(work: Ptr<Unit>): ULong
54/**
55 * Runs prepared system-trust loading work synchronously. The work pointer must remain valid until
56 * execution finishes.
57 */
58@Extern(name = "scoop_tls_system_context_run")
59public fun runSystemContext(work: Ptr<Unit>)
61/**
62 * Releases an owned system-trust work record and any result not already taken. Call once after its
63 * execution has stopped.
64 */
65@Extern(name = "scoop_tls_system_context_free")
66public fun freeSystemContext(work: Ptr<Unit>)
68@Extern(name = "scoop_tls_verification_take")
69internal fun takeVerification(handle: ULong): NativeTlsWork
71@Extern(name = "scoop_tls_verification_complete")
72internal fun completeVerification(handle: ULong, work: Ptr<Unit>): CryptoResult
74/**
75 * Runs an owned TLS certificate-verification work record synchronously.
76 */
77@Extern(name = "scoop_tls_verification_run")
78public 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")
84public fun freeVerification(work: Ptr<Unit>)