Skip to content

Commit

Permalink
Update to Swift 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley committed Sep 12, 2017
1 parent b4f00c0 commit b96e740
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
49 changes: 40 additions & 9 deletions SwCrypt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0800;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = irl;
TargetAttributes = {
A051E37A1DBA5DA3004293E9 = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0900;
ProvisioningStyle = Manual;
SystemCapabilities = {
com.apple.Keychain = {
Expand All @@ -223,11 +224,11 @@
};
A0A71E771CBC7D74002C5C88 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
A0A71E811CBC7D74002C5C88 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
TestTargetID = A051E37A1DBA5DA3004293E9;
};
};
Expand Down Expand Up @@ -355,7 +356,8 @@
PRODUCT_BUNDLE_IDENTIFIER = hu.irl.dummyTestApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -374,7 +376,8 @@
PRODUCT_BUNDLE_IDENTIFIER = hu.irl.dummyTestApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -387,13 +390,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -421,6 +432,8 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -436,13 +449,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -462,6 +483,9 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -473,6 +497,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -484,14 +509,16 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
A0A71E8E1CBC7D74002C5C88 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -502,7 +529,8 @@
PRODUCT_BUNDLE_IDENTIFIER = hu.irl.SwCrypt;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -513,7 +541,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = hu.irl.SwCryptTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/dummyTestApp.app/dummyTestApp";
};
name = Debug;
Expand All @@ -525,7 +554,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = hu.irl.SwCryptTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/dummyTestApp.app/dummyTestApp";
};
name = Release;
Expand All @@ -540,6 +570,7 @@
A051E38B1DBA5DA4004293E9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
A0A71E721CBC7D74002C5C88 /* Build configuration list for PBXProject "SwCrypt" */ = {
isa = XCConfigurationList;
Expand Down
4 changes: 3 additions & 1 deletion SwCrypt.xcodeproj/xcshareddata/xcschemes/SwCrypt.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
13 changes: 5 additions & 8 deletions SwCrypt/SwCrypt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ open class PEM {
throw SwError(.parse("iv"))
}
let aesKey = getAESKey(mode, passphrase: passphrase, iv: iv)
let base64Data = strippedKey.substring(
from: strippedKey.index(strippedKey.startIndex, offsetBy:aesHeaderLength))
let base64Data = String(strippedKey[strippedKey.index(strippedKey.startIndex, offsetBy: aesHeaderLength)...])

guard let data = PEM.base64Decode(base64Data) else {
throw SwError(.parse("base64decode"))
}
Expand Down Expand Up @@ -505,10 +505,7 @@ open class PEM {
}

fileprivate static func getIV(_ strippedKey: String) -> Data? {
let ivInHex = strippedKey.substring(
with: strippedKey.index(strippedKey.startIndex,
offsetBy:aesInfoLength) ..< strippedKey.index(strippedKey.startIndex,
offsetBy:aesHeaderLength))
let ivInHex = String(strippedKey[strippedKey.index(strippedKey.startIndex, offsetBy: aesInfoLength) ..< strippedKey.index(strippedKey.startIndex, offsetBy: aesHeaderLength)])
return ivInHex.dataFromHexadecimalString()
}

Expand Down Expand Up @@ -569,7 +566,7 @@ open class PEM {
guard let r = data.range(of: footer) else {
return nil
}
return data.substring(with: header.endIndex..<r.lowerBound)
return String(data[header.endIndex ..< r.lowerBound])
}

fileprivate static func base64Decode(_ base64Data: String) -> Data? {
Expand Down Expand Up @@ -2104,7 +2101,7 @@ extension String {
var index: String.Index? = trimmedString.startIndex

while let i = index {
let byteString = trimmedString.substring(with: i ..< trimmedString.index(i, offsetBy: 2))
let byteString = String(trimmedString[i ..< trimmedString.index(i, offsetBy: 2)])
let num = UInt8(byteString.withCString { strtoul($0, nil, 16) })
data.append([num] as [UInt8], count: 1)

Expand Down
4 changes: 2 additions & 2 deletions SwCryptTests/SwCryptTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class SwCryptTest: XCTestCase {
}

func decryptOpenSSLKeys(_ type: String) {
let bundle = Bundle(for: type(of: self))
let bundle = Bundle(for: Swift.type(of: self))
let encPEM = bundle.object(forInfoDictionaryKey: "testPrivEncryptedPEMAES" + type) as! String
let decPEM = bundle.object(forInfoDictionaryKey: "testPrivDecryptedPEM") as! String
let d = try? SwKeyConvert.PrivateKey.decryptPEM(encPEM, passphrase: "hello")
Expand All @@ -121,7 +121,7 @@ class SwCryptTest: XCTestCase {
}

func decryptOpenSSLKeysBadPassphrase(_ type: String) {
let bundle = Bundle(for: type(of: self))
let bundle = Bundle(for: Swift.type(of: self))
let encPEM = bundle.object(forInfoDictionaryKey: "testPrivEncryptedPEMAES" + type) as! String

XCTAssertThrowsError(try SwKeyConvert.PrivateKey.decryptPEM(encPEM, passphrase: "nohello")) {
Expand Down

0 comments on commit b96e740

Please sign in to comment.