Skip to content

Commit 3e3ba60

Browse files
committed
bump websocket version
1 parent a32f2d3 commit 3e3ba60

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

Source/SSLSecurity.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Starscream
55
//
66
// Created by Dalton Cherry on 5/16/15.
7-
// Copyright (c) 2014-2015 Dalton Cherry.
7+
// Copyright (c) 2014-2016 Dalton Cherry.
88
//
99
// Licensed under the Apache License, Version 2.0 (the "License");
1010
// you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
import Foundation
2424
import Security
2525

26-
public class SSLCert : NSObject {
26+
open class SSLCert {
2727
var certData: Data?
2828
var key: SecKey?
2929

@@ -50,7 +50,7 @@ public class SSLCert : NSObject {
5050
}
5151
}
5252

53-
public class SSLSecurity : NSObject {
53+
open class SSLSecurity {
5454
public var validatedDN = true //should the domain name be validated?
5555

5656
var isReady = false //is the key processing done?
@@ -82,16 +82,14 @@ public class SSLSecurity : NSObject {
8282
/**
8383
Designated init
8484

85-
- parameter keys: is the certificates or public keys to use
85+
- parameter certs: is the certificates or public keys to use
8686
- parameter usePublicKeys: is to specific if the publicKeys or certificates should be used for SSL pinning validation
8787

8888
- returns: a representation security object to be used with
8989
*/
9090
public init(certs: [SSLCert], usePublicKeys: Bool) {
9191
self.usePublicKeys = usePublicKeys
9292

93-
super.init()
94-
9593
if self.usePublicKeys {
9694
DispatchQueue.global(qos: .default).async {
9795
let pubKeys = certs.reduce([SecKey]()) { (pubKeys: [SecKey], cert: SSLCert) -> [SecKey] in

Source/WebSocket.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Websocket.swift
44
//
55
// Created by Dalton Cherry on 7/16/14.
6-
// Copyright (c) 2014-2015 Dalton Cherry.
6+
// Copyright (c) 2014-2016 Dalton Cherry.
77
//
88
// Licensed under the Apache License, Version 2.0 (the "License");
99
// you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ public protocol WebSocketPongDelegate: class {
3838
func websocketDidReceivePong(socket: WebSocket, data: Data?)
3939
}
4040

41-
public class WebSocket : NSObject, StreamDelegate {
41+
open class WebSocket : NSObject, StreamDelegate {
4242

4343
enum OpCode : UInt8 {
4444
case continueFrame = 0x0
@@ -190,15 +190,19 @@ public class WebSocket : NSObject, StreamDelegate {
190190

191191
/**
192192
Disconnect from the server. I send a Close control frame to the server, then expect the server to respond with a Close control frame and close the socket from its end. I notify my delegate once the socket has been closed.
193+
193194
If you supply a non-nil `forceTimeout`, I wait at most that long (in seconds) for the server to close the socket. After the timeout expires, I close the socket and notify my delegate.
195+
194196
If you supply a zero (or negative) `forceTimeout`, I immediately close the socket (without sending a Close control frame) and notify my delegate.
197+
195198
- Parameter forceTimeout: Maximum time to wait for the server to close the socket.
196199
- Parameter closeCode: The code to send on disconnect. The default is the normal close code for cleanly disconnecting a webSocket.
197200
*/
198201
public func disconnect(forceTimeout: TimeInterval? = nil, closeCode: UInt16 = CloseCode.normal.rawValue) {
199202
switch forceTimeout {
200203
case .some(let seconds) where seconds > 0:
201-
callbackQueue.asyncAfter(deadline: DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) { [weak self] in
204+
let milliseconds = Int(seconds * 1_000)
205+
callbackQueue.asyncAfter(deadline: .now() + .milliseconds(milliseconds)) { [weak self] in
202206
self?.disconnectStream(nil)
203207
}
204208
fallthrough
@@ -212,8 +216,10 @@ public class WebSocket : NSObject, StreamDelegate {
212216

213217
/**
214218
Write a string to the websocket. This sends it as a text frame.
219+
215220
If you supply a non-nil completion block, I will perform it when the write completes.
216-
- parameter str: The string to write.
221+
222+
- parameter string: The string to write.
217223
- parameter completion: The (optional) completion handler.
218224
*/
219225
public func write(string: String, completion: (() -> ())? = nil) {
@@ -223,7 +229,9 @@ public class WebSocket : NSObject, StreamDelegate {
223229

224230
/**
225231
Write binary data to the websocket. This sends it as a binary frame.
232+
226233
If you supply a non-nil completion block, I will perform it when the write completes.
234+
227235
- parameter data: The data to write.
228236
- parameter completion: The (optional) completion handler.
229237
*/
@@ -358,7 +366,7 @@ public class WebSocket : NSObject, StreamDelegate {
358366
self.mutex.unlock()
359367

360368
let bytes = UnsafeRawPointer((data as NSData).bytes).assumingMemoryBound(to: UInt8.self)
361-
var out = timeout * 1000000 // wait 5 seconds before giving up
369+
var out = timeout * 1_000_000 // wait 5 seconds before giving up
362370
writeQueue.addOperation { [weak self] in
363371
while !outStream.hasSpaceAvailable {
364372
usleep(100) // wait until the socket is ready
@@ -380,9 +388,9 @@ public class WebSocket : NSObject, StreamDelegate {
380388
*/
381389
public func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
382390
if let sec = security, !certValidated && [.hasBytesAvailable, .hasSpaceAvailable].contains(eventCode) {
383-
let trust = aStream.property(forKey: kCFStreamPropertySSLPeerTrust as Stream.PropertyKey) as AnyObject
391+
let trust = aStream.property(forKey: kCFStreamPropertySSLPeerTrust as Stream.PropertyKey) as! SecTrust
384392
let domain = aStream.property(forKey: kCFStreamSSLPeerName as Stream.PropertyKey) as? String
385-
if sec.isValid(trust as! SecTrust, domain: domain) {
393+
if sec.isValid(trust, domain: domain) {
386394
certValidated = true
387395
} else {
388396
let error = errorWithDetail("Invalid SSL certificate", code: 1)

0 commit comments

Comments
 (0)