Scoop API

scoop:scoop.tls:0.1.0

src/wrap.scoop

Selected production source · src/wrap.scoop

1package scoop.tls
3import scoop.platform.io.*
4import scoop.platform.memory.NativeByteBuffer
5import scoop.tls.native.TlsEngine
7internal fun <T> adoptSync(engine: TlsEngine, transport: T): TlsStream
8 where T : ByteSource, T : ByteSink, T : Closeable {
9 val owner: Closeable = transport
10 val pump: SyncPump = try { allocatePump(engine, transport, transport) }
11 catch (error: Throwable) {
12 val resources: Array<Closeable> = [owner, engine]
13 when (closeAll(resources)) {
14 case Some(val cleanup) -> throw ResourceUseException(error, cleanup)
15 case None -> throw error
16 }
17 }
18 val stream = TlsStream(pump, transport)
19 stream.handshake()
20 return stream
23private fun allocatePump(engine: TlsEngine, source: ByteSource, sink: ByteSink): SyncPump {
24 val input = NativeByteBuffer.allocate(16384L)
25 try { return SyncPump(engine, source, sink, input, NativeByteBuffer.allocate(16384L)) }
26 catch (error: Throwable) { input.close(); throw error }