0001    //	====================================================================
0002    //
0003    //	Copyright (c) 2007-2008, Eric Rescorla and Derek MacDonald
0004    //	All rights reserved.
0005    //
0006    //	Redistribution and use in source and binary forms, with or without
0007    //	modification, are permitted provided that the following conditions are
0008    //	met:
0009    //
0010    //	1. Redistributions of source code must retain the above copyright
0011    //	   notice, this list of conditions and the following disclaimer.
0012    //
0013    //	2. Redistributions in binary form must reproduce the above copyright
0014    //	   notice, this list of conditions and the following disclaimer in the
0015    //	   documentation and/or other materials provided with the distribution.
0016    //
0017    //	3. None of the contributors names may be used to endorse or promote
0018    //	   products derived from this software without specific prior written
0019    //	   permission.
0020    //
0021    //	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0022    //	"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0023    //	LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0024    //	A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0025    //	OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0026    //	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0027    //	LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0028    //	DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0029    //	THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0030    //	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0031    //	OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0032    //
0033    //	====================================================================
0034    
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