/
expect.kt
48 lines (39 loc) · 1.7 KB
/
expect.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.koushikdutta.scratch.tls
import com.koushikdutta.scratch.IOException
import com.koushikdutta.scratch.buffers.AllocationTracker
import com.koushikdutta.scratch.buffers.ByteBufferList
import com.koushikdutta.scratch.buffers.WritableBuffers
class SSLEngineResult constructor(val status: SSLEngineStatus, val handshakeStatus: SSLEngineHandshakeStatus)
enum class SSLEngineStatus {
BUFFER_UNDERFLOW,
OK,
CLOSED,
}
enum class SSLEngineHandshakeStatus {
FINISHED,
NEED_TASK,
NEED_UNWRAP,
NEED_WRAP,
}
expect class SSLContext {
fun createSSLEngine(): SSLEngine
fun createSSLEngine(host: String?, port: Int): SSLEngine
}
typealias SSLEngineTask = () -> Unit
expect abstract class SSLEngine {
abstract fun getUseClientMode(): Boolean
abstract fun setUseClientMode(value: Boolean)
}
expect fun SSLEngine.runHandshakeTask()
expect fun SSLEngine.checkHandshakeStatus(): SSLEngineHandshakeStatus
expect fun SSLEngine.unwrap(src: ByteBufferList, dst: WritableBuffers, tracker: AllocationTracker = AllocationTracker()): SSLEngineResult
expect fun SSLEngine.wrap(src: ByteBufferList, dst: WritableBuffers, tracker: AllocationTracker = AllocationTracker()): SSLEngineResult
expect open class SSLException(message: String): IOException
expect class SSLHandshakeException : SSLException
expect interface RSAPrivateKey
expect abstract class X509Certificate
expect fun createSelfSignedCertificate(subjectName: String): Pair<RSAPrivateKey, X509Certificate>
expect fun SSLContext.init(pk: RSAPrivateKey, certificate: X509Certificate): SSLContext
expect fun SSLContext.init(certificate: X509Certificate): SSLContext
expect fun createTLSContext(): SSLContext
expect fun getDefaultSSLContext(): SSLContext