0001 // SSLIO.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDINbG BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 import COpenSSL 0026 @_exported import File 0027 0028 public class IO{ 0029 0030 public enum Error
ClientStream.swift:33 private let readIO: IOClientStream.swift:34 private let writeIO: IOKey.swift:36 let bio = try IO(filePath: filePath)ServerStream.swift:32 private let readIO: IOServerStream.swift:33 private let writeIO: IOSession.swift:96 public func setIO(readIO readIO: IO, writeIO: IO) {Session.swift:96 public func setIO(readIO readIO: IO, writeIO: IO) {: ErrorType { 0031 case BIO
IO.swift:60 throw Error.BIO(description: lastSSLErrorDescription)IO.swift:71 throw Error.ShouldRetry(description: lastSSLErrorDescription)IO.swift:73 throw Error.BIO(description: lastSSLErrorDescription)IO.swift:96 throw Error.ShouldRetry(description: lastSSLErrorDescription)IO.swift:98 throw Error.BIO(description: lastSSLErrorDescription)(description: String) 0032 case ShouldRetry
IO.swift:60 throw Error.BIO(description: lastSSLErrorDescription)IO.swift:73 throw Error.BIO(description: lastSSLErrorDescription)IO.swift:98 throw Error.BIO(description: lastSSLErrorDescription)(description: String) 0033 case UnsupportedMethod(description: String) 0034 } 0035 0036 public enum Method
ClientStream.swift:95 } catch IO.Error.ShouldRetry {ClientStream.swift:109 } catch IO.Error.ShouldRetry {}IO.swift:71 throw Error.ShouldRetry(description: lastSSLErrorDescription)IO.swift:96 throw Error.ShouldRetry(description: lastSSLErrorDescription)ServerStream.swift:100 } catch IO.Error.ShouldRetry {{ 0037 case Memory
IO.swift:55 public init(method: Method) throws {0038 0039 var method
IO.swift:41 case .Memory:IO.swift:50 try self.init(method: .Memory): UnsafeMutablePointer<BIO_METHOD> { 0040 switch self { 0041 case .Memory: 0042 return BIO_s_mem() 0043 } 0044 } 0045 } 0046 0047 var bio
IO.swift:57 bio = BIO_new(method.method): UnsafeMutablePointer<BIO> 0048 0049 public convenience init
IO.swift:57 bio = BIO_new(method.method)IO.swift:59 if bio == nil {IO.swift:81 return BIO_ctrl_pending(bio)IO.swift:85 return (bio.memory.flags & BIO_FLAGS_SHOULD_RETRY) != 0Key.swift:37 self.key = PEM_read_bio_PrivateKey(bio.bio, nil, nil, nil)Session.swift:97 SSL_set_bio(ssl, readIO.bio, writeIO.bio)Session.swift:97 SSL_set_bio(ssl, readIO.bio, writeIO.bio)(filePath: String) throws { 0050 try self.init(method: .Memory) 0051 let file = try File(path: filePath) 0052 try write(file.read()) 0053 } 0054 0055 public init
Key.swift:36 let bio = try IO(filePath: filePath)(method: Method) throws { 0056 OpenSSL.initialize() 0057 bio = BIO_new(method.method) 0058 0059 if bio == nil { 0060 throw Error.BIO(description: lastSSLErrorDescription) 0061 } 0062 } 0063 0064 public func write(data: Data) throws -> Int { 0065 let result = data.withUnsafeBufferPointer { 0066 BIO_write(bio, $0.baseAddress, Int32($0.count)) 0067 } 0068 0069 if result < 0 { 0070 if shouldRetry { 0071 throw Error.ShouldRetry(description: lastSSLErrorDescription) 0072 } else { 0073 throw Error.BIO(description: lastSSLErrorDescription) 0074 } 0075 } 0076 0077 return Int(result) 0078 } 0079 0080 public var pending: Int { 0081 return BIO_ctrl_pending(bio) 0082 } 0083 0084 public var shouldRetry
IO.swift:50 try self.init(method: .Memory): Bool { 0085 return (bio.memory.flags & BIO_FLAGS_SHOULD_RETRY) != 0 0086 } 0087 0088 public func read() throws -> Data { 0089 var data = Data.bufferWithSize(DEFAULT_BUFFER_SIZE) 0090 let result = data.withUnsafeMutableBufferPointer { 0091 BIO_read(bio, $0.baseAddress, Int32($0.count)) 0092 } 0093 0094 if result < 0 { 0095 if shouldRetry { 0096 throw Error.ShouldRetry(description: lastSSLErrorDescription) 0097 } else { 0098 throw Error.BIO(description: lastSSLErrorDescription) 0099 } 0100 } 0101 0102 return data.prefix(Int(result)) 0103 } 0104 } 0105
IO.swift:70 if shouldRetry {IO.swift:95 if shouldRetry {