From 8019e57b34c97e613382ae57b43aabf612075223 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Wed, 6 Jun 2018 20:11:55 -0400 Subject: [PATCH 01/11] Rename the CommonCrypto module shim, and only import it if needed The iOS 12 SDK now provides a module map for CommonCrypto. Using `#if canImport(CommonCrypto)` and the module map shims allows for correct compilation with both the old and new SDKs --- CommonCrypto/appletvos/module.modulemap | 2 +- CommonCrypto/appletvsimulator/module.modulemap | 2 +- CommonCrypto/iphoneos/module.modulemap | 2 +- CommonCrypto/iphonesimulator/module.modulemap | 2 +- CommonCrypto/macosx/module.modulemap | 2 +- CommonCrypto/watchos/module.modulemap | 2 +- CommonCrypto/watchsimulator/module.modulemap | 2 +- Sources/Crypto.swift | 4 ++++ 8 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CommonCrypto/appletvos/module.modulemap b/CommonCrypto/appletvos/module.modulemap index c4fac3a1..5289f57e 100644 --- a/CommonCrypto/appletvos/module.modulemap +++ b/CommonCrypto/appletvos/module.modulemap @@ -1,4 +1,4 @@ -module CommonCrypto [system] { +module CommonCryptoShim [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * } diff --git a/CommonCrypto/appletvsimulator/module.modulemap b/CommonCrypto/appletvsimulator/module.modulemap index d1728b66..a0c4f03b 100644 --- a/CommonCrypto/appletvsimulator/module.modulemap +++ b/CommonCrypto/appletvsimulator/module.modulemap @@ -1,4 +1,4 @@ -module CommonCrypto [system] { +module CommonCryptoShim [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * } diff --git a/CommonCrypto/iphoneos/module.modulemap b/CommonCrypto/iphoneos/module.modulemap index 125b7720..0d53e895 100644 --- a/CommonCrypto/iphoneos/module.modulemap +++ b/CommonCrypto/iphoneos/module.modulemap @@ -1,4 +1,4 @@ -module CommonCrypto [system] { +module CommonCryptoShim [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * } diff --git a/CommonCrypto/iphonesimulator/module.modulemap b/CommonCrypto/iphonesimulator/module.modulemap index 835d6863..787e5f16 100644 --- a/CommonCrypto/iphonesimulator/module.modulemap +++ b/CommonCrypto/iphonesimulator/module.modulemap @@ -1,4 +1,4 @@ -module CommonCrypto [system] { +module CommonCryptoShim [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * } diff --git a/CommonCrypto/macosx/module.modulemap b/CommonCrypto/macosx/module.modulemap index 9ceb81cc..40b7cfc9 100644 --- a/CommonCrypto/macosx/module.modulemap +++ b/CommonCrypto/macosx/module.modulemap @@ -1,4 +1,4 @@ -module CommonCrypto [system] { +module CommonCryptoShim [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * } diff --git a/CommonCrypto/watchos/module.modulemap b/CommonCrypto/watchos/module.modulemap index e81b2c61..152f247a 100644 --- a/CommonCrypto/watchos/module.modulemap +++ b/CommonCrypto/watchos/module.modulemap @@ -1,4 +1,4 @@ -module CommonCrypto [system] { +module CommonCryptoShim [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * } diff --git a/CommonCrypto/watchsimulator/module.modulemap b/CommonCrypto/watchsimulator/module.modulemap index e1cfc7f9..2e6e21b1 100644 --- a/CommonCrypto/watchsimulator/module.modulemap +++ b/CommonCrypto/watchsimulator/module.modulemap @@ -1,4 +1,4 @@ -module CommonCrypto [system] { +module CommonCryptoShim [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/CommonCrypto/CommonCrypto.h" export * } diff --git a/Sources/Crypto.swift b/Sources/Crypto.swift index d2e7c84f..40c28ee4 100644 --- a/Sources/Crypto.swift +++ b/Sources/Crypto.swift @@ -24,7 +24,11 @@ // import Foundation +#if canImport(CommonCrypto) import CommonCrypto +#else +import CommonCryptoShim +#endif func HMAC(algorithm: Generator.Algorithm, key: Data, data: Data) -> Data { let (hashFunction, hashLength) = algorithm.hashInfo From 5364a181bced39ccb14db8c31a87cf8afc25aa38 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Wed, 6 Jun 2018 20:38:12 -0400 Subject: [PATCH 02/11] Add conditional compilation to re-enable Swift 4.0 support --- Sources/Crypto.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Crypto.swift b/Sources/Crypto.swift index 40c28ee4..3a154099 100644 --- a/Sources/Crypto.swift +++ b/Sources/Crypto.swift @@ -24,10 +24,14 @@ // import Foundation -#if canImport(CommonCrypto) -import CommonCrypto +#if swift(>=4.1) + #if canImport(CommonCrypto) + import CommonCrypto + #else + import CommonCryptoShim + #endif #else -import CommonCryptoShim + import CommonCryptoShim #endif func HMAC(algorithm: Generator.Algorithm, key: Data, data: Data) -> Data { From 413b2631baf0ea959f09902d4aeff768452b013f Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 14 Sep 2018 15:47:02 -0400 Subject: [PATCH 03/11] [Travis] Use Xcode 10 for CI builds and tests by default Also, add an extra Xcode 9.4 build to ensure backwards compatibility. --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cddaa703..1ecdef1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,12 +5,12 @@ language: objective-c xcode_workspace: OneTimePassword.xcworkspace xcode_scheme: OneTimePassword (iOS) -osx_image: xcode9.3 +osx_image: xcode10 env: - - RUNTIME="iOS 9.3" DEVICE="iPhone 6s" - RUNTIME="iOS 10.3" DEVICE="iPhone 7 Plus" - RUNTIME="iOS 11.3" DEVICE="iPhone X" + - RUNTIME="iOS 12.0" DEVICE="iPhone XS Max" # Include builds for watchOS matrix: @@ -21,6 +21,9 @@ matrix: # Include an Xcode 9.2 build to test on iOS 8.x, because Xcode 9.3's iOS 8 simulator fails to launch - osx_image: xcode9.2 env: RUNTIME="iOS 8.4" DEVICE="iPhone 4s" + # Include an Xcode 9.4 build to ensure compatibility until Xcode 10 is in widespread use + - osx_image: xcode9.4 + env: RUNTIME="iOS 9.3" DEVICE="iPhone 6s" # Include several build-only jobs for watchOS - xcode_scheme: OneTimePassword (watchOS) env: BUILD_ONLY="YES" RUNTIME="watchOS 4.3" DEVICE="Apple Watch Series 3 - 38mm" From c5623c4d27be9551522bd867d0abd42777a12d33 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 14 Sep 2018 15:55:36 -0400 Subject: [PATCH 04/11] [Travis] Add a new Apple Watch CI build --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1ecdef1f..49d3b663 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,11 +26,14 @@ matrix: env: RUNTIME="iOS 9.3" DEVICE="iPhone 6s" # Include several build-only jobs for watchOS - xcode_scheme: OneTimePassword (watchOS) + env: BUILD_ONLY="YES" RUNTIME="watchOS 5.0" DEVICE="Apple Watch Series 4 - 44mm" + - xcode_scheme: OneTimePassword (watchOS) + osx_image: xcode9.4 env: BUILD_ONLY="YES" RUNTIME="watchOS 4.3" DEVICE="Apple Watch Series 3 - 38mm" - xcode_scheme: OneTimePassword (watchOS) env: BUILD_ONLY="YES" RUNTIME="watchOS 3.2" DEVICE="Apple Watch Series 2 - 42mm" - xcode_scheme: OneTimePassword (watchOS) - env: BUILD_ONLY="YES" RUNTIME="watchOS 2.2" DEVICE="Apple Watch - 38mm" + env: BUILD_ONLY="YES" RUNTIME="watchOS 2.0" DEVICE="Apple Watch - 38mm" # Check out nested dependencies before_install: git submodule update --init --recursive From 4a8c2c310ac96729d8e93048729ab2a04ccebf8a Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 14 Sep 2018 16:13:34 -0400 Subject: [PATCH 05/11] Remove an unnecessary explicit call to .init() --- Sources/Keychain.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Keychain.swift b/Sources/Keychain.swift index ff1637b8..30f4d637 100644 --- a/Sources/Keychain.swift +++ b/Sources/Keychain.swift @@ -52,7 +52,7 @@ public final class Keychain { // tokens as possible. // TODO: Restore deserialization error handling, in a way that provides info on the failure reason and allows // the caller to choose whether to fail completely or recover some data. - return Set(allItems.flatMap({ try? PersistentToken.init(keychainDictionary:$0) })) + return Set(allItems.flatMap({ try? PersistentToken(keychainDictionary:$0) })) } // MARK: Write From fd9059515b9e566ffb281fe475945404e0d5880d Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 14 Sep 2018 16:20:22 -0400 Subject: [PATCH 06/11] Enable new SwiftLint rules, including consistent modifier order --- .swiftlint.yml | 7 +++++++ OneTimePasswordLegacyTests/OTPToken.swift | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 86fc1ea4..435c171c 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -9,14 +9,17 @@ opt_in_rules: - closure_spacing - conditional_returns_on_newline - contains_over_first_not_nil + - convenience_type - discouraged_object_literal - discouraged_optional_boolean - discouraged_optional_collection - empty_count - empty_string + - empty_xctest_method - explicit_enum_raw_value - explicit_init - extension_access_modifier + - fallthrough - fatal_error_message - file_header - first_where @@ -26,18 +29,22 @@ opt_in_rules: - let_var_whitespace - literal_expression_end_indentation - lower_acl_than_parent + - modifier_order + - multiline_function_chains - multiline_parameters - nimble_operator - operator_usage_whitespace - overridden_super_call - override_in_extension - pattern_matching_keywords + - private_action - private_outlet - prohibited_super_call - redundant_nil_coalescing - single_test_class - sorted_first_last - switch_case_on_newline + - unavailable_function - unneeded_parentheses_in_closure_argument - untyped_error_in_catch - vertical_parameter_alignment_on_call diff --git a/OneTimePasswordLegacyTests/OTPToken.swift b/OneTimePasswordLegacyTests/OTPToken.swift index 195bf2cb..70d09abd 100644 --- a/OneTimePasswordLegacyTests/OTPToken.swift +++ b/OneTimePasswordLegacyTests/OTPToken.swift @@ -30,7 +30,7 @@ import OneTimePassword /// information about its properties and methods, consult the underlying `OneTimePassword` /// documentation. public final class OTPToken: NSObject { - required public override init() {} + override public required init() {} @objc public var name: String = OTPToken.defaultName @objc public var issuer: String = OTPToken.defaultIssuer From 97736ff83a3a4c1b8285efc68a9a4f28d381ab96 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 14 Sep 2018 16:55:17 -0400 Subject: [PATCH 07/11] [Lint] Clean up whitespace around colons --- Sources/Keychain.swift | 10 +++++----- Tests/KeychainTests.swift | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Keychain.swift b/Sources/Keychain.swift index 30f4d637..b2c9d1a8 100644 --- a/Sources/Keychain.swift +++ b/Sources/Keychain.swift @@ -52,7 +52,7 @@ public final class Keychain { // tokens as possible. // TODO: Restore deserialization error handling, in a way that provides info on the failure reason and allows // the caller to choose whether to fail completely or recover some data. - return Set(allItems.flatMap({ try? PersistentToken(keychainDictionary:$0) })) + return Set(allItems.flatMap({ try? PersistentToken(keychainDictionary: $0) })) } // MARK: Write @@ -180,7 +180,7 @@ private func addKeychainItem(withAttributes attributes: [String: AnyObject]) thr private func updateKeychainItem(forPersistentRef persistentRef: Data, withAttributes attributesToUpdate: [String: AnyObject]) throws { - let queryDict: [String : AnyObject] = [ + let queryDict: [String: AnyObject] = [ kSecClass as String: kSecClassGenericPassword, kSecValuePersistentRef as String: persistentRef as NSData, ] @@ -193,7 +193,7 @@ private func updateKeychainItem(forPersistentRef persistentRef: Data, } private func deleteKeychainItem(forPersistentRef persistentRef: Data) throws { - let queryDict: [String : AnyObject] = [ + let queryDict: [String: AnyObject] = [ kSecClass as String: kSecClassGenericPassword, kSecValuePersistentRef as String: persistentRef as NSData, ] @@ -206,7 +206,7 @@ private func deleteKeychainItem(forPersistentRef persistentRef: Data) throws { } private func keychainItem(forPersistentRef persistentRef: Data) throws -> NSDictionary? { - let queryDict: [String : AnyObject] = [ + let queryDict: [String: AnyObject] = [ kSecClass as String: kSecClassGenericPassword, kSecValuePersistentRef as String: persistentRef as NSData, kSecReturnPersistentRef as String: kCFBooleanTrue, @@ -233,7 +233,7 @@ private func keychainItem(forPersistentRef persistentRef: Data) throws -> NSDict } private func allKeychainItems() throws -> [NSDictionary] { - let queryDict: [String : AnyObject] = [ + let queryDict: [String: AnyObject] = [ kSecClass as String: kSecClassGenericPassword, kSecMatchLimit as String: kSecMatchLimitAll, kSecReturnPersistentRef as String: kCFBooleanTrue, diff --git a/Tests/KeychainTests.swift b/Tests/KeychainTests.swift index 5d90daa1..e1ede6e2 100644 --- a/Tests/KeychainTests.swift +++ b/Tests/KeychainTests.swift @@ -319,7 +319,7 @@ private func addKeychainItem(withAttributes attributes: [String: AnyObject]) thr } public func deleteKeychainItem(forPersistentRef persistentRef: Data) throws { - let queryDict: [String : AnyObject] = [ + let queryDict: [String: AnyObject] = [ kSecClass as String: kSecClassGenericPassword, kSecValuePersistentRef as String: persistentRef as NSData, ] From 82739441c5f81993bbe7f937f60bed4dbef95f14 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 14 Sep 2018 17:14:21 -0400 Subject: [PATCH 08/11] [Lint] Re-enable colon linting, with flexible right spacing --- .swiftlint.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 435c171c..b20e6ccd 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -50,11 +50,13 @@ opt_in_rules: - vertical_parameter_alignment_on_call - yoda_condition disabled_rules: - - colon - comma - cyclomatic_complexity - identifier_name +colon: + flexible_right_spacing: true + trailing_comma: mandatory_comma: true From 9d49e1563d118898cb08c9e23b081837307b4504 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Fri, 14 Sep 2018 17:16:50 -0400 Subject: [PATCH 09/11] [Lint] Re-enable comma linting, with selective disabling --- .swiftlint.yml | 1 - Tests/GeneratorTests.swift | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index b20e6ccd..352d86c7 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -50,7 +50,6 @@ opt_in_rules: - vertical_parameter_alignment_on_call - yoda_condition disabled_rules: - - comma - cyclomatic_complexity - identifier_name diff --git a/Tests/GeneratorTests.swift b/Tests/GeneratorTests.swift index d2449f65..d9e60fa0 100644 --- a/Tests/GeneratorTests.swift +++ b/Tests/GeneratorTests.swift @@ -73,11 +73,13 @@ class GeneratorTests: XCTestCase { func testCounter() { let factors: [(TimeInterval, TimeInterval, UInt64)] = [ + // swiftlint:disable comma (100, 30, 3), (10000, 30, 333), (1000000, 30, 33333), (100000000, 60, 1666666), (10000000000, 90, 111111111), + // swiftlint:enable comma ] for (timeSinceEpoch, period, count) in factors { From ccc9bd7d5263491b2aaae2c78a498034bf5bec01 Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Sat, 15 Sep 2018 20:13:25 -0400 Subject: [PATCH 10/11] Bump the version number to 3.1.4 --- OneTimePassword.podspec | 2 +- Sources/Info.plist | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OneTimePassword.podspec b/OneTimePassword.podspec index 0d0fc894..01c5ae37 100644 --- a/OneTimePassword.podspec +++ b/OneTimePassword.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "OneTimePassword" - s.version = "3.1.3" + s.version = "3.1.4" s.summary = "A small library for generating TOTP and HOTP one-time passwords." s.homepage = "https://github.com/mattrubin/OneTimePassword" s.license = "MIT" diff --git a/Sources/Info.plist b/Sources/Info.plist index fa3725f0..78223678 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.1.3 + 3.1.4 CFBundleSignature ???? CFBundleVersion - 3.1.3 + 3.1.4 NSPrincipalClass From 0f2aa62161670cbc0628e8e1c2580f5a7105550d Mon Sep 17 00:00:00 2001 From: Matt Rubin Date: Sat, 15 Sep 2018 21:06:56 -0400 Subject: [PATCH 11/11] Update the changelog --- CHANGELOG.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 775cc84c..bc7f723b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ +## [3.1.4][] (2018-09-15) +- Fix compilation errors and add CI testing for Xcode 10. +([#182](https://github.com/mattrubin/OneTimePassword/pull/182), +[#186](https://github.com/mattrubin/OneTimePassword/pull/186)) +- Enable several new SwiftLint opt-in rules. ([#187](https://github.com/mattrubin/OneTimePassword/pull/187)) + + ## [3.1.3][] (2018-04-29) - Ignore un-deserializable tokens in `allPersistentTokens()`. ([#179](https://github.com/mattrubin/OneTimePassword/pull/179)) @@ -159,8 +166,9 @@ Changes between prerelease versions of OneTimePassword version 2 can be found be ## [1.0.0][] (2014-07-17) -[develop]: https://github.com/mattrubin/OneTimePassword/compare/3.1.3...develop +[develop]: https://github.com/mattrubin/OneTimePassword/compare/3.1.4...develop +[3.1.4]: https://github.com/mattrubin/OneTimePassword/compare/3.1.3...3.1.4 [3.1.3]: https://github.com/mattrubin/OneTimePassword/compare/3.1.2...3.1.3 [3.1.2]: https://github.com/mattrubin/OneTimePassword/compare/3.1.1...3.1.2 [3.1.1]: https://github.com/mattrubin/OneTimePassword/compare/3.1...3.1.1