0001
0035 import System
0036 import COpenSSL
0037
0038 public let BIO_TYPE_DWRAP| DWrap.swift:40 | private var methods_dwrap = BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in |
: Int32 = (50 | 0x0400 | 0x0200)
0039
0040 private var methods_dwrap| DWrap.swift:49 | return getPointer(&methods_dwrap) |
= BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in
0041 return BIO_callback_ctrl(bio.memory.next_bio, cmd, fp)
0042 })
0043
0044 private func getPointer| DWrap.swift:49 | return getPointer(&methods_dwrap) |
<T>(arg: UnsafeMutablePointer<T>) -> UnsafeMutablePointer<T> {
0045 return arg
0046 }
0047
0048 public func BIO_f_dwrap() -> UnsafeMutablePointer<BIO_METHOD> {
0049 return getPointer(&methods_dwrap)
0050 }
0051
0052 func OPENSSL_malloc| DWrap.swift:70 | let ctx = OPENSSL_malloc(sizeof(BIO_F_DWRAP_CTX)) |
(num: Int, file: String = #file, line: Int = #line) -> UnsafeMutablePointer<Void> {
0053 return CRYPTO_malloc(Int32(num), file, Int32(line))
0054 }
0055
0056 func OPENSSL_free| DWrap.swift:84 | OPENSSL_free(bio.memory.ptr) |
(ptr: UnsafeMutablePointer<Void>) {
0057 CRYPTO_free(ptr)
0058 }
0059
0060 let BIO_FLAGS_RWS| DWrap.swift:62 | BIO_clear_flags(b, BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY) |
= (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
0061 func BIO_clear_retry_flags| DWrap.swift:95 | BIO_clear_retry_flags(bio) |
(b: UnsafeMutablePointer<BIO>) {
0062 BIO_clear_flags(b, BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)
0063 }
0064
0065 private struct BIO_F_DWRAP_CTX| DWrap.swift:70 | let ctx = OPENSSL_malloc(sizeof(BIO_F_DWRAP_CTX)) |
| DWrap.swift:73 | memset(ctx, 0, sizeof(BIO_F_DWRAP_CTX)) |
| DWrap.swift:120 | let ctx = UnsafeMutablePointer<BIO_F_DWRAP_CTX>(bio.memory.ptr) |
{
0066 var dgram_timer_exp| DWrap.swift:124 | if ctx.memory.dgram_timer_exp { |
| DWrap.swift:126 | ctx.memory.dgram_timer_exp = false |
| DWrap.swift:131 | ctx.memory.dgram_timer_exp = true |
: Bool
0067 }
0068
0069 private func dwrap_new| DWrap.swift:40 | private var methods_dwrap = BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in |
(bio: UnsafeMutablePointer<BIO>) -> Int32 {
0070 let ctx = OPENSSL_malloc(sizeof(BIO_F_DWRAP_CTX))
0071 guard ctx != nil else { return 0 }
0072
0073 memset(ctx, 0, sizeof(BIO_F_DWRAP_CTX))
0074
0075 let b = bio.memory
0076 bio.memory = BIO(method: b.method, callback: b.callback, cb_arg: b.cb_arg, init: 1, shutdown: b.shutdown, flags: 0, retry_reason: b.retry_reason, num: b.num, ptr: ctx, next_bio: b.next_bio, prev_bio: b.prev_bio, references: b.references, num_read: b.num_read, num_write: b.num_write, ex_data: b.ex_data)
0077
0078 return 1
0079 }
0080
0081 private func dwrap_free| DWrap.swift:40 | private var methods_dwrap = BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in |
(bio: UnsafeMutablePointer<BIO>) -> Int32 {
0082 if bio == nil { return 0 }
0083
0084 OPENSSL_free(bio.memory.ptr)
0085
0086 let b = bio.memory
0087 bio.memory = BIO(method: b.method, callback: b.callback, cb_arg: b.cb_arg, init: 0, shutdown: b.shutdown, flags: 0, retry_reason: b.retry_reason, num: b.num, ptr: nil, next_bio: b.next_bio, prev_bio: b.prev_bio, references: b.references, num_read: b.num_read, num_write: b.num_write, ex_data: b.ex_data)
0088
0089 return 1
0090 }
0091
0092 private func dwrap_read| DWrap.swift:40 | private var methods_dwrap = BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in |
(bio: UnsafeMutablePointer<BIO>, data: UnsafeMutablePointer<Int8>, length: Int32) -> Int32 {
0093 guard bio != nil && data != nil else { return 0 }
0094
0095 BIO_clear_retry_flags(bio)
0096
0097 let ret = BIO_read(bio.memory.next_bio, data, length)
0098
0099 if ret <= 0 {
0100 BIO_copy_next_retry(bio)
0101 }
0102
0103 return ret
0104 }
0105
0106 private func dwrap_write| DWrap.swift:40 | private var methods_dwrap = BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in |
(bio: UnsafeMutablePointer<BIO>, data: UnsafePointer<Int8>, length: Int32) -> Int32 {
0107 guard bio != nil && data != nil && length > 0 else { return 0 }
0108 return BIO_write(bio.memory.next_bio, data, length)
0109 }
0110
0111 private func dwrap_puts| DWrap.swift:40 | private var methods_dwrap = BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in |
(bio: UnsafeMutablePointer<BIO>, data: UnsafePointer<Int8>) -> Int32 {
0112 fatalError()
0113 }
0114
0115 private func dwrap_gets| DWrap.swift:40 | private var methods_dwrap = BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in |
(bio: UnsafeMutablePointer<BIO>, data: UnsafeMutablePointer<Int8>, length: Int32) -> Int32 {
0116 fatalError()
0117 }
0118
0119 private func dwrap_ctrl| DWrap.swift:40 | private var methods_dwrap = BIO_METHOD(type: BIO_TYPE_DWRAP, name: "dtls_wrapper", bwrite: dwrap_write, bread: dwrap_read, bputs: dwrap_puts, bgets: dwrap_gets, ctrl: dwrap_ctrl, create: dwrap_new, destroy: dwrap_free, callback_ctrl: { bio, cmd, fp in |
(bio: UnsafeMutablePointer<BIO>, cmd: Int32, num: Int, ptr: UnsafeMutablePointer<Void>) -> Int {
0120 let ctx = UnsafeMutablePointer<BIO_F_DWRAP_CTX>(bio.memory.ptr)
0121 var ret: Int
0122 switch cmd {
0123 case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP:
0124 if ctx.memory.dgram_timer_exp {
0125 ret = 1
0126 ctx.memory.dgram_timer_exp = false
0127 } else {
0128 ret = 0
0129 }
0130 case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
0131 ctx.memory.dgram_timer_exp = true
0132 ret = 1
0133 default:
0134 ret = BIO_ctrl(bio.memory.next_bio, cmd, num, ptr)
0135 }
0136 return ret
0137 }
0138