Merge branch 'xcode-migrations'

This commit is contained in:
Davide De Rosa 2019-03-30 23:19:27 +01:00
commit 49dd0a8403
23 changed files with 129 additions and 82 deletions

View File

@ -370,7 +370,7 @@
TargetAttributes = {
0EB39FE51F7424F80023AFFC = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
@ -383,7 +383,7 @@
};
0EB39FFB1F7425140023AFFC = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
@ -396,6 +396,7 @@
};
0EB6EEB61F92D417005F6221 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.ApplicationGroups.Mac = {
@ -414,6 +415,7 @@
};
0EB6EECA1F92D43D005F6221 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.ApplicationGroups.Mac = {
@ -837,6 +839,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.algoritmico.ios.demo.BasicTunnel;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@ -853,6 +856,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.algoritmico.ios.demo.BasicTunnel;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@ -869,6 +873,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.algoritmico.ios.demo.BasicTunnel.BasicTunnelExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@ -885,6 +890,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.algoritmico.ios.demo.BasicTunnel.BasicTunnelExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@ -905,6 +911,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@ -924,6 +931,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SWIFT_VERSION = 5.0;
};
name = Release;
};
@ -942,6 +950,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@ -960,6 +969,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
};
name = Release;
};

View File

@ -1,13 +1,13 @@
PODS:
- OpenSSL-Apple (1.1.0i.2)
- SwiftyBeaver (1.6.2)
- TunnelKit (1.5.1):
- TunnelKit/AppExtension (= 1.5.1)
- TunnelKit/Core (= 1.5.1)
- TunnelKit/AppExtension (1.5.1):
- SwiftyBeaver (1.7.0)
- TunnelKit (1.5.2):
- TunnelKit/AppExtension (= 1.5.2)
- TunnelKit/Core (= 1.5.2)
- TunnelKit/AppExtension (1.5.2):
- SwiftyBeaver
- TunnelKit/Core
- TunnelKit/Core (1.5.1):
- TunnelKit/Core (1.5.2):
- OpenSSL-Apple (~> 1.1.0i.2)
- SwiftyBeaver
@ -25,8 +25,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
OpenSSL-Apple: 37a8c0b04df4bb8971deef4671cc29222861319c
SwiftyBeaver: 8e67ab3cd94389cbbb7a9c7cc02748d98bfee68e
TunnelKit: fb4db4d4c4b36af0ca8e973e3345a1c3ef5ac85c
SwiftyBeaver: 4cc0080d2e23f980652e28978db11a5c9da39165
TunnelKit: 9d8089c4600ea9b3a54841391b4969f2faa9c17f
PODFILE CHECKSUM: f66dfaaa92a8d04ab2743f3caeab0ac9f9f25859

View File

@ -1,6 +1,6 @@
PODS:
- OpenSSL-Apple (1.1.0i.2)
- SwiftyBeaver (1.6.2)
- SwiftyBeaver (1.7.0)
DEPENDENCIES:
- OpenSSL-Apple (~> 1.1.0i.2)
@ -13,7 +13,7 @@ SPEC REPOS:
SPEC CHECKSUMS:
OpenSSL-Apple: 37a8c0b04df4bb8971deef4671cc29222861319c
SwiftyBeaver: 8e67ab3cd94389cbbb7a9c7cc02748d98bfee68e
SwiftyBeaver: 4cc0080d2e23f980652e28978db11a5c9da39165
PODFILE CHECKSUM: b66d2624e26ea150d992a8457747267128054176

View File

@ -7,7 +7,7 @@ Pod::Spec.new do |s|
s.license = { :type => "GPLv3", :file => "LICENSE" }
s.author = { "Davide De Rosa" => "keeshux@gmail.com" }
s.source = { :git => "https://github.com/keeshux/tunnelkit.git", :tag => "v#{s.version}" }
s.swift_version = "4.2"
s.swift_version = "5.0"
s.ios.deployment_target = "11.0"
s.osx.deployment_target = "10.11"

View File

@ -880,13 +880,13 @@
TargetAttributes = {
0E1108991F77B9E800A92462 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
TestTargetID = 0E1108A81F77B9F900A92462;
};
0E1108A81F77B9F900A92462 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
@ -899,15 +899,17 @@
};
0E17D7F81F730D9F009EE129 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
0E3251C41F95770D00C108D9 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
0EA82A222190B220007960EB = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
@ -1359,6 +1361,7 @@
INFOPLIST_FILE = "TunnelKitTests-iOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TunnelKitHost.app/TunnelKitHost";
};
@ -1370,6 +1373,7 @@
INFOPLIST_FILE = "TunnelKitTests-iOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TunnelKitHost.app/TunnelKitHost";
};
@ -1387,7 +1391,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.algoritmico.ios.TunnelKitHost;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@ -1404,7 +1408,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.algoritmico.ios.TunnelKitHost;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@ -1549,6 +1553,7 @@
PRODUCT_NAME = TunnelKit;
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/TunnelKit/Sources";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@ -1572,6 +1577,7 @@
PRODUCT_NAME = TunnelKit;
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/TunnelKit/Sources";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@ -1596,6 +1602,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/TunnelKit/Sources";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@ -1619,6 +1626,7 @@
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/TunnelKit/Sources";
SWIFT_VERSION = 5.0;
};
name = Release;
};
@ -1638,6 +1646,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
@ -1656,6 +1665,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx;
SWIFT_VERSION = 5.0;
};
name = Release;
};

View File

@ -76,7 +76,8 @@ public class DNSResolver {
var ipAddresses: [String] = []
for case var rawAddress as Data in rawAddresses {
var ipAddress = [CChar](repeating: 0, count: Int(NI_MAXHOST))
let result = rawAddress.withUnsafeBytes { (addr: UnsafePointer<sockaddr>) in
let result: Int32 = rawAddress.withUnsafeBytes {
let addr = $0.bindMemory(to: sockaddr.self).baseAddress!
return getnameinfo(
addr,
socklen_t(rawAddress.count),
@ -99,7 +100,8 @@ public class DNSResolver {
var addr = in_addr(s_addr: CFSwapInt32HostToBig(ipv4))
var buf = Data(count: Int(INET_ADDRSTRLEN))
let bufCount = socklen_t(buf.count)
let resultPtr = buf.withUnsafeMutableBytes { (bufPtr) in
let resultPtr: UnsafePointer<CChar>? = buf.withUnsafeMutableBytes {
let bufPtr = $0.bindMemory(to: CChar.self).baseAddress!
return withUnsafePointer(to: &addr) {
return inet_ntop(AF_INET, $0, bufPtr, bufCount)
}

View File

@ -48,6 +48,7 @@ extension NWTCPConnectionState: CustomStringConvertible {
case .disconnected: return "disconnected"
case .invalid: return "invalid"
case .waiting: return "waiting"
@unknown default: return "???"
}
}
}

View File

@ -48,6 +48,7 @@ extension NWUDPSessionState: CustomStringConvertible {
case .preparing: return "preparing"
case .ready: return "ready"
case .waiting: return "waiting"
@unknown default: return "???"
}
}
}

View File

@ -595,7 +595,7 @@ extension EndpointProtocol: Codable {
/// :nodoc:
public extension UserDefaults {
@objc public var dataCountArray: [Int]? {
@objc var dataCountArray: [Int]? {
get {
return array(forKey: TunnelKitProvider.Configuration.dataCountKey) as? [Int]
}
@ -604,7 +604,7 @@ public extension UserDefaults {
}
}
public func removeDataCountArray() {
func removeDataCountArray() {
removeObject(forKey: TunnelKitProvider.Configuration.dataCountKey)
}
}

View File

@ -56,7 +56,7 @@ extension TunnelKitProvider {
public let data: Data
private init(_ byte: UInt8) {
data = Data(bytes: [byte])
data = Data([byte])
}
init(_ data: Data) {

View File

@ -166,7 +166,7 @@ open class TunnelKitProvider: NEPacketTunnelProvider {
if let content = cfg.existingLog(in: appGroup) {
var existingLog = content.components(separatedBy: "\n")
if let i = existingLog.index(of: logSeparator) {
if let i = existingLog.firstIndex(of: logSeparator) {
existingLog.removeFirst(i + 2)
}
@ -627,6 +627,9 @@ extension TunnelKitProvider {
case .LZO:
return .lzo
default:
break
}
} else if let se = error as? SessionError {
switch se {

View File

@ -192,7 +192,8 @@ extension ControlChannel {
// needs a copy for swapping
var authPacket = packet
let authCount = authPacket.count
try authPacket.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer<UInt8>) in
try authPacket.withUnsafeMutableBytes {
let ptr = $0.bytePointer
PacketSwapCopy(ptr, packet, prefixLength, authLength)
try decrypter.verifyBytes(ptr, length: authCount, flags: nil)
}
@ -265,9 +266,11 @@ extension ControlChannel {
let encryptedCount = packet.count - adLength
var decryptedPacket = Data(count: decrypter.encryptionCapacity(withLength: encryptedCount))
var decryptedCount = 0
try packet.withUnsafeBytes { (src: UnsafePointer<UInt8>) in
try packet.withUnsafeBytes {
let src = $0.bytePointer
var flags = CryptoFlags(iv: nil, ivLength: 0, ad: src, adLength: adLength)
try decryptedPacket.withUnsafeMutableBytes { (dest: UnsafeMutablePointer<UInt8>) in
try decryptedPacket.withUnsafeMutableBytes {
let dest = $0.bytePointer
try decrypter.decryptBytes(src + flags.adLength, length: encryptedCount, dest: dest + headerLength, destLength: &decryptedCount, flags: &flags)
memcpy(dest, src, headerLength)
}

View File

@ -115,9 +115,10 @@ extension CustomStringConvertible {
return description
}
var data = description.data(using: .utf8)!
let dataCount = CC_LONG(data.count)
var md = Data(count: Int(CC_SHA1_DIGEST_LENGTH))
md.withUnsafeMutableBytes {
_ = CC_SHA1(&data, CC_LONG(data.count), $0)
_ = CC_SHA1(&data, dataCount, $0.bytePointer)
}
return "#\(md.toHex().prefix(16))#"
}

View File

@ -66,7 +66,7 @@ extension Data {
}
bytes[index >> 1] |= nibble
}
self = Data(bytes: bytes)
self = Data(bytes)
}
func toHex() -> String {
@ -164,7 +164,9 @@ extension Data {
// best
func UInt32Value(from: Int) -> UInt32 {
return subdata(in: from..<(from + 4)).withUnsafeBytes { $0.pointee }
return subdata(in: from..<(from + 4)).withUnsafeBytes {
$0.load(as: UInt32.self)
}
}
@available(*, deprecated)
@ -182,13 +184,13 @@ extension Data {
func networkUInt16Value(from: Int) -> UInt16 {
return UInt16(bigEndian: subdata(in: from..<(from + 2)).withUnsafeBytes {
$0.pointee
$0.load(as: UInt16.self)
})
}
func networkUInt32Value(from: Int) -> UInt32 {
return UInt32(bigEndian: subdata(in: from..<(from + 4)).withUnsafeBytes {
$0.pointee
$0.load(as: UInt32.self)
})
}
}
@ -204,3 +206,15 @@ extension Array where Element == Data {
return map { $0.count }.reduce(0) { $0 + $1 }
}
}
extension UnsafeRawBufferPointer {
var bytePointer: UnsafePointer<Element> {
return bindMemory(to: Element.self).baseAddress!
}
}
extension UnsafeMutableRawBufferPointer {
var bytePointer: UnsafeMutablePointer<Element> {
return bindMemory(to: Element.self).baseAddress!
}
}

View File

@ -156,6 +156,7 @@ extension PacketCode: CustomStringConvertible {
case .hardResetServerV2: return "HARD_RESET_SERVER_V2"
case .dataV2: return "DATA_V2"
case .unknown: return "UNKNOWN"
@unknown default: return "UNKNOWN"
}
}
}

View File

@ -77,8 +77,9 @@ class SecureRandom {
static func data(length: Int) throws -> Data {
var randomData = Data(count: length)
try randomData.withUnsafeMutableBytes { (randomBytes: UnsafeMutablePointer<UInt8>) -> Void in
guard (SecRandomCopyBytes(kSecRandomDefault, length, randomBytes) == 0) else {
try randomData.withUnsafeMutableBytes {
let randomBytes = $0.bytePointer
guard SecRandomCopyBytes(kSecRandomDefault, length, randomBytes) == 0 else {
throw SecureRandomError.randomGenerator
}
}

View File

@ -42,7 +42,7 @@ import __TunnelKitNative
private let log = SwiftyBeaver.self
fileprivate extension ZeroingData {
fileprivate func appendSized(_ buf: ZeroingData) {
func appendSized(_ buf: ZeroingData) {
append(Z(UInt16(buf.count).bigEndian))
append(buf)
}

View File

@ -41,7 +41,7 @@ class CompressionTests: XCTestCase {
func testSymmetric() {
XCTAssertTrue(LZOIsSupported());
let lzo = LZOCreate()
let src = Data(bytes: [UInt8](repeating: 6, count: 100))
let src = Data([UInt8](repeating: 6, count: 100))
guard let dst = try? lzo.compressedData(with: src) else {
XCTFail("Uncompressible data")
return

View File

@ -64,7 +64,7 @@ class ConfigurationParserTests: XCTestCase {
// XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"]))
XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["compress"]))
XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["compress lzo"]))
XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["compress lzo"]))
}
func testDHCPOption() throws {

View File

@ -56,10 +56,10 @@ class DataManipulationTests: XCTestCase {
XCTAssertEqual(data.UInt16Value(from: 4), 0x6655)
XCTAssertEqual(data.UInt32Value(from: 0), 0xbbaaff22)
XCTAssertEqual(data.UInt16Value(from: 3), data.UInt16ValueFromPointers(from: 3))
XCTAssertEqual(data.UInt32Value(from: 2), data.UInt32ValueFromBuffer(from: 2))
XCTAssertEqual(data.UInt16Value(from: 4), data.UInt16ValueFromPointers(from: 4))
XCTAssertEqual(data.UInt32Value(from: 0), data.UInt32ValueFromBuffer(from: 0))
// XCTAssertEqual(data.UInt16Value(from: 3), data.UInt16ValueFromPointers(from: 3))
// XCTAssertEqual(data.UInt32Value(from: 2), data.UInt32ValueFromBuffer(from: 2))
// XCTAssertEqual(data.UInt16Value(from: 4), data.UInt16ValueFromPointers(from: 4))
// XCTAssertEqual(data.UInt32Value(from: 0), data.UInt32ValueFromBuffer(from: 0))
}
func testZeroingData() {

View File

@ -77,27 +77,27 @@ class LinkTests: XCTestCase {
bytes.append(contentsOf: [0xaa])
XCTAssertEqual(bytes.count, 21)
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 18)
XCTAssertEqual(packets.count, 3)
bytes.append(contentsOf: [0xbb, 0xcc])
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 23)
XCTAssertEqual(packets.count, 4)
bytes.append(contentsOf: [0x00, 0x05])
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 23)
XCTAssertEqual(packets.count, 4)
bytes.append(contentsOf: [0x11, 0x22, 0x33, 0x44])
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 23)
XCTAssertEqual(packets.count, 4)
bytes.append(contentsOf: [0x55])
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 30)
XCTAssertEqual(packets.count, 5)
@ -108,7 +108,7 @@ class LinkTests: XCTestCase {
bytes.append(contentsOf: [0x00, 0x04])
bytes.append(contentsOf: [0x10, 0x20])
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 0)
XCTAssertEqual(packets.count, 0)
bytes.removeSubrange(0..<until)
@ -117,7 +117,7 @@ class LinkTests: XCTestCase {
bytes.append(contentsOf: [0x30, 0x40])
bytes.append(contentsOf: [0x00, 0x07])
bytes.append(contentsOf: [0x10, 0x20, 0x30, 0x40])
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 6)
XCTAssertEqual(packets.count, 1)
bytes.removeSubrange(0..<until)
@ -128,14 +128,14 @@ class LinkTests: XCTestCase {
bytes.append(contentsOf: [0xff])
bytes.append(contentsOf: [0x00, 0x03])
bytes.append(contentsOf: [0xaa])
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 12)
XCTAssertEqual(packets.count, 2)
bytes.removeSubrange(0..<until)
XCTAssertEqual(bytes.count, 3)
bytes.append(contentsOf: [0xbb, 0xcc])
(until, packets) = PacketStream.packets(from: Data(bytes: bytes))
(until, packets) = PacketStream.packets(from: Data(bytes))
XCTAssertEqual(until, 5)
XCTAssertEqual(packets.count, 1)
bytes.removeSubrange(0..<until)

View File

@ -61,27 +61,27 @@ class RawPerformanceTests: XCTestCase {
}
}
// 0.463s
func testUInt16FromPointers() {
let data = Data([0x22, 0xff, 0xaa, 0xbb, 0x55, 0x66])
measure {
for _ in 0..<1000000 {
let _ = data.UInt16ValueFromPointers(from: 3)
}
}
}
// 0.863s
func testUInt32FromBuffer() {
let data = Data([0x22, 0xff, 0xaa, 0xbb, 0x55, 0x66])
measure {
for _ in 0..<1000000 {
let _ = data.UInt32ValueFromBuffer(from: 1)
}
}
}
// // 0.463s
// func testUInt16FromPointers() {
// let data = Data([0x22, 0xff, 0xaa, 0xbb, 0x55, 0x66])
//
// measure {
// for _ in 0..<1000000 {
// let _ = data.UInt16ValueFromPointers(from: 3)
// }
// }
// }
//
// // 0.863s
// func testUInt32FromBuffer() {
// let data = Data([0x22, 0xff, 0xaa, 0xbb, 0x55, 0x66])
//
// measure {
// for _ in 0..<1000000 {
// let _ = data.UInt32ValueFromBuffer(from: 1)
// }
// }
// }
// 0.469s
func testUInt32FromPointers() {
@ -94,14 +94,14 @@ class RawPerformanceTests: XCTestCase {
}
}
// 0.071s
func testRandomUInt32FromBuffer() {
measure {
for _ in 0..<10000 {
let _ = try! SecureRandom.uint32FromBuffer()
}
}
}
// // 0.071s
// func testRandomUInt32FromBuffer() {
// measure {
// for _ in 0..<10000 {
// let _ = try! SecureRandom.uint32FromBuffer()
// }
// }
// }
// 0.063s
func testRandomUInt32FromPointers() {

View File

@ -62,7 +62,7 @@ extension Encrypter {
var dest: [UInt8] = Array(repeating: 0, count: srcLength + 256)
var destLength = 0
try data.withUnsafeBytes {
try encryptBytes($0, length: srcLength, dest: &dest, destLength: &destLength, flags: flags)
try encryptBytes($0.bytePointer, length: srcLength, dest: &dest, destLength: &destLength, flags: flags)
}
dest.removeSubrange(destLength..<dest.count)
return Data(dest)
@ -75,7 +75,7 @@ extension Decrypter {
var dest: [UInt8] = Array(repeating: 0, count: srcLength + 256)
var destLength = 0
try data.withUnsafeBytes {
try decryptBytes($0, length: srcLength, dest: &dest, destLength: &destLength, flags: flags)
try decryptBytes($0.bytePointer, length: srcLength, dest: &dest, destLength: &destLength, flags: flags)
}
dest.removeSubrange(destLength..<dest.count)
return Data(dest)
@ -84,7 +84,7 @@ extension Decrypter {
func verifyData(_ data: Data, flags: UnsafePointer<CryptoFlags>?) throws {
let srcLength = data.count
try data.withUnsafeBytes {
try verifyBytes($0, length: srcLength, flags: flags)
try verifyBytes($0.bytePointer, length: srcLength, flags: flags)
}
}
}