Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
upgrade to swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
btoews committed Sep 25, 2018
1 parent 8fb9b41 commit 9ae2d4b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
16 changes: 6 additions & 10 deletions APDU/Data/DataReader.swift
Expand Up @@ -88,25 +88,21 @@ public class DataReader {
}

// Read n bytes from the data, advancing our offset into the data.
func readData<I:Integer>(_ n: I) throws -> Data {
let intN = Int(n.toIntMax())

guard let d = peekData(intN) else {
func readData<I:BinaryInteger>(_ n: I) throws -> Data {
guard let d = peekData(n) else {
throw DataReaderError.End
}

offset += intN
offset += Int(n)
return d
}

// Read n bytes from the data, without advancing our offset into the data.
func peekData<I:Integer>(_ n: I) -> Data? {
let intN = Int(n.toIntMax())

if remaining < intN {
func peekData<I:BinaryInteger>(_ n: I) -> Data? {
if remaining < n {
return nil
}

return rest.subdata(in: 0..<intN)
return rest.subdata(in: 0..<Int(n))
}
}
38 changes: 25 additions & 13 deletions SoftU2F.xcodeproj/project.pbxproj
Expand Up @@ -723,7 +723,7 @@
51F0900B1E37E8C600F03AD3 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = VEKTX9H2N7;
LastSwiftMigration = 0820;
LastSwiftMigration = 1000;
ProvisioningStyle = Manual;
SystemCapabilities = {
com.apple.Keychain = {
Expand All @@ -734,7 +734,7 @@
51F0901C1E37E8C600F03AD3 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = VEKTX9H2N7;
LastSwiftMigration = 0820;
LastSwiftMigration = 1000;
ProvisioningStyle = Manual;
TestTargetID = 51F0900B1E37E8C600F03AD3;
};
Expand All @@ -751,12 +751,13 @@
F738F4F01E4A2CCB005680A2 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = VEKTX9H2N7;
LastSwiftMigration = 0800;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
F738F52E1E4A2E8A005680A2 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = VEKTX9H2N7;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
F738F5591E4A31DE005680A2 = {
Expand All @@ -767,6 +768,7 @@
F738F5701E4A3328005680A2 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = VEKTX9H2N7;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -1132,7 +1134,8 @@
PROVISIONING_PROFILE_SPECIFIER = SoftU2FTool;
SWIFT_OBJC_BRIDGING_HEADER = "SoftU2FTool/SoftU2F-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -1155,7 +1158,8 @@
PROVISIONING_PROFILE = "0d639ce7-4261-41e5-8e5d-8a39cdfc8c41";
PROVISIONING_PROFILE_SPECIFIER = SoftU2FTool;
SWIFT_OBJC_BRIDGING_HEADER = "SoftU2FTool/SoftU2F-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -1177,7 +1181,8 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "SoftU2FToolTests/SoftU2FTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SoftU2F.app/Contents/MacOS/SoftU2F";
};
name = Debug;
Expand All @@ -1199,7 +1204,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "SoftU2FToolTests/SoftU2FTests-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SoftU2F.app/Contents/MacOS/SoftU2F";
};
name = Release;
Expand Down Expand Up @@ -1286,7 +1292,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -1313,7 +1320,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.github.APDU;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -1330,7 +1338,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.github.APDUTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -1345,7 +1354,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.github.APDUTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down Expand Up @@ -1424,7 +1434,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.github.SelfSignedCertificateTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -1439,7 +1450,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.github.SelfSignedCertificateTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
4 changes: 2 additions & 2 deletions SoftU2FTool/AppDelegate.swift
Expand Up @@ -31,10 +31,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// Chrome ignores our U2F responses if it isn't active when we send them.
// This hack should give focus back to Chrome immediately after the user interacts
// with our notification.
NSApplication.shared().hide(nil)
NSApplication.shared.hide(nil)
}

private func quit() {
NSApplication.shared().terminate(self)
NSApplication.shared.terminate(self)
}
}
11 changes: 7 additions & 4 deletions SoftU2FTool/U2FAuthenticator.swift
Expand Up @@ -33,10 +33,8 @@ class U2FAuthenticator {
}

private var laptopIsOpen: Bool {
guard let screens = NSScreen.screens() else { return true }

return screens.contains { screen in
guard let screenID = screen.deviceDescription["NSScreenNumber"] as? uint32 else { return true }
return NSScreen.screens.contains { screen in
guard let screenID = convertFromNSDeviceDescriptionKeyDictionary(screen.deviceDescription)["NSScreenNumber"] as? uint32 else { return true }
return CGDisplayIsBuiltin(screenID) == 1
}
}
Expand Down Expand Up @@ -214,3 +212,8 @@ class U2FAuthenticator {
let _ = u2fhid.sendMsg(cid: cid, data: msg.raw)
}
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromNSDeviceDescriptionKeyDictionary(_ input: [NSDeviceDescriptionKey: Any]) -> [String: Any] {
return Dictionary(uniqueKeysWithValues: input.map {key, value in (key.rawValue, value)})
}

0 comments on commit 9ae2d4b

Please sign in to comment.