Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Swift 3 #91

Merged
merged 47 commits into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d886089
Add whitespace between parameter names and arguments
mattrubin Jul 22, 2016
6fc6c8f
Remove extra newlines at the beginning of types
mattrubin Jul 22, 2016
191acbb
Merge pull request #79 from mattrubin/whitespace
mattrubin Jul 22, 2016
482bff6
Add Codecov reporting to the Travis CI configuration
mattrubin Aug 29, 2016
4f4a184
Add Codecov configuration to ignore coverage of the test code
mattrubin Aug 29, 2016
4dfa6c4
Add Codecov badge to the readme
mattrubin Aug 29, 2016
a08a830
Merge pull request #82 from mattrubin/code-coverage
mattrubin Aug 29, 2016
187bcda
Updating to recommended xcode 8 project settings
mike-engel Sep 8, 2016
6b36f17
Merge pull request #84 from mike-engel/master
mattrubin Sep 19, 2016
9b34687
Update the changelog with post-2.0 changes
mattrubin Sep 19, 2016
1afcbb5
Group changelog entries into "Added" and "Changed"
mattrubin Sep 19, 2016
6ae7a18
Reorganize changelog entries into "Enhancements", "Fixes", and "Other…
mattrubin Sep 19, 2016
ed28e96
Add links to pull requests for recent changelog entries
mattrubin Sep 19, 2016
19fc5d3
Style subheadings in the changelog
mattrubin Sep 19, 2016
96f7fe9
Add a section for 2.0.1 to the changelog
mattrubin Sep 19, 2016
75a809a
Add the project name to the top of the changelog
mattrubin Sep 19, 2016
25c99cf
Hide the (currently empty) "In development" section from the changelog
mattrubin Sep 19, 2016
a4c34d0
Update SwiftLint configuration for SwiftLint 0.12.0
mattrubin Sep 19, 2016
0293bee
Enable the vertical_whitespace SwiftLint rule
mattrubin Sep 19, 2016
2e41dc5
Merge pull request #87 from mattrubin/swiftlint
mattrubin Sep 19, 2016
c5dca2b
Add changelog entry for PR #87
mattrubin Sep 19, 2016
62c3247
Update the note regarding keychain tests on iOS 10
mattrubin Sep 19, 2016
89fe82a
Note that the keychain test issue is specifically in iOS 10
mattrubin Sep 19, 2016
f4370aa
Merge pull request #88 from mattrubin/keychain-tests
mattrubin Sep 19, 2016
2f755c0
Add a changelog link to PR #88
mattrubin Sep 19, 2016
c1c8574
Make Xcode 8 the default configuration for Travis tests
mattrubin Sep 19, 2016
32f565e
Move Travis iOS 8.x tests back to Xcode 7.3
mattrubin Sep 19, 2016
bec0bfc
Disable duplicate iOS 10.0 tests
mattrubin Sep 19, 2016
11b2b76
Clean up Travis test destinations
mattrubin Sep 19, 2016
e21ac55
Merge pull request #89 from mattrubin/travis-xcode-8
mattrubin Sep 19, 2016
fea6522
Add changelog entry for updated Travis configuration
mattrubin Sep 19, 2016
708a514
Replace "2.0.1" with "In development" in the Changelog until release
mattrubin Sep 19, 2016
187251a
Fix "In Development" diff link in the changelog
mattrubin Sep 19, 2016
53bf537
Correct changelog punctuation
mattrubin Sep 19, 2016
26d3766
Merge branch 'master' into changelog
mattrubin Sep 19, 2016
ad5f37e
Merge pull request #86 from mattrubin/changelog
mattrubin Sep 20, 2016
e297187
Update the framework version number to 2.0.1
mattrubin Sep 20, 2016
fcc2a51
Update the changelog with a section for version 2.0.1
mattrubin Sep 20, 2016
9f0ecd6
Update the podspec version number to 2.0.1
mattrubin Sep 20, 2016
81ca3b8
Update the 2.0.1 release date in the changelog
mattrubin Sep 20, 2016
854257b
Merge pull request #90 from mattrubin/release-2.0.1
mattrubin Sep 20, 2016
45c8993
Merge swift-2.3 into swift-3
mattrubin Sep 20, 2016
6adfa10
Fix compilation errors with the release version of Xcode 8
mattrubin Sep 20, 2016
960175e
Fix compilation errors in tests with the release version of Xcode 8
mattrubin Sep 20, 2016
4b6b8df
Clean up long line
mattrubin Sep 20, 2016
28aaad3
Disable xcpretty to diagnose an issue with Travis test timeouts
mattrubin Sep 20, 2016
0ac7fa8
Disable Travis builds for iOS 8.x with Xcode 8
mattrubin Sep 20, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Configuration for Codecov (https://codecov.io)

coverage:
ignore:
- "Tests"
- "OneTimePasswordLegacyTests"
4 changes: 2 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

excluded:
- Carthage
enabled_rules:
opt_in_rules:
- empty_count
# - missing_docs
- vertical_whitespace
disabled_rules:
- comma
- conditional_binding_cascade
- cyclomatic_complexity
- function_body_length
- line_length
Expand Down
20 changes: 13 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ osx_image: xcode8
xcode_sdk: iphonesimulator10.0

env:
- DESTINATION="OS=10.0,name=iPhone 5"
- DESTINATION="OS=10.0,name=iPhone 6S Plus"
- DESTINATION="OS=10.0,name=iPhone SE"
- DESTINATION="OS=10.0,name=iPad Retina"
- DESTINATION="OS=10.0,name=iPad Pro (12.9 inch)"
# iOS 8 builds time out with Xcode 8
# - DESTINATION="OS=8.1,name=iPhone 4S"
# - DESTINATION="OS=8.2,name=iPhone 5"
# - DESTINATION="OS=8.3,name=iPhone 5S"
# - DESTINATION="OS=8.4,name=iPhone 6"
- DESTINATION="OS=9.0,name=iPhone 6"
- DESTINATION="OS=9.1,name=iPhone 6 Plus"
- DESTINATION="OS=9.2,name=iPhone 6S"
- DESTINATION="OS=9.3,name=iPhone 6S Plus"
- DESTINATION="OS=10.0,name=iPhone 7"

# Check out nested dependencies
before_install: git submodule update --init --recursive

# A custom test script is required because xctool cannot access the iOS keychain
# https://github.com/facebook/xctool/issues/269
script: set -o pipefail && xcodebuild -workspace $TRAVIS_XCODE_WORKSPACE -scheme $TRAVIS_XCODE_SCHEME -sdk $TRAVIS_XCODE_SDK -destination "$DESTINATION" build test | xcpretty -c

after_success:
- bash <(curl -s https://codecov.io/bash)
24 changes: 21 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
# Changelog
# OneTimePassword Changelog

<!--## [In development][master]-->

## [2.0.1][] (2016-09-20)
#### Enhancements
- Update the project to support Xcode 8 and Swift 2.3. ([#73](https://github.com/mattrubin/OneTimePassword/pull/73), [#75](https://github.com/mattrubin/OneTimePassword/pull/75), [#84](https://github.com/mattrubin/OneTimePassword/pull/84))

#### Fixes
- Disable broken keychain tests on iOS 10. ([#77](https://github.com/mattrubin/OneTimePassword/pull/77), [#88](https://github.com/mattrubin/OneTimePassword/pull/88))

#### Other Changes
- Update badge images and links in the README. ([#69](https://github.com/mattrubin/OneTimePassword/pull/69))
- Reorganize source and test files following the conventions the Swift Package Manager. ([#70](https://github.com/mattrubin/OneTimePassword/pull/70))
- Isolate the CommonCrypto dependency inside a custom wrapper function. ([#71](https://github.com/mattrubin/OneTimePassword/pull/71))
- Clean up whitespace. ([#79](https://github.com/mattrubin/OneTimePassword/pull/79))
- Integrate with codecov.io for automated code coverage reporting. ([#82](https://github.com/mattrubin/OneTimePassword/pull/82))
- Update SwiftLint configuration. ([#87](https://github.com/mattrubin/OneTimePassword/pull/87))
- Update Travis configuration to use Xcode 8. ([#89](https://github.com/mattrubin/OneTimePassword/pull/89))


## [2.0.0][] (2016-02-07)

Version 2 of the OneTimePassword library has been completely redesigned and rewritten with a modern Swift API. The new library source differs too greatly from its predecessor for the changes to be representable in a changelog. The README has a usage guide for the new API.
Expand Down Expand Up @@ -63,8 +80,9 @@ Changes between prerelease versions of OneTimePassword version 2 can be found be

## [1.0.0][] (2014-07-17)

[master]: https://github.com/mattrubin/OneTimePassword/compare/2.0.0...master
[master]: https://github.com/mattrubin/OneTimePassword/compare/2.0.1...master

[2.0.1]: https://github.com/mattrubin/OneTimePassword/compare/2.0.0...2.0.1
[2.0.0]: https://github.com/mattrubin/OneTimePassword/compare/1.1.0...2.0.0
[2.0.0-rc]: https://github.com/mattrubin/OneTimePassword/compare/2.0.0-beta.5...2.0.0
[2.0.0-beta.5]: https://github.com/mattrubin/OneTimePassword/compare/2.0.0-beta.4...2.0.0-beta.5
Expand All @@ -75,4 +93,4 @@ Changes between prerelease versions of OneTimePassword version 2 can be found be
[2.0.0-beta]: https://github.com/mattrubin/OneTimePassword/compare/1.1.1...2.0.0-beta
[1.1.1]: https://github.com/mattrubin/OneTimePassword/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/mattrubin/OneTimePassword/compare/1.0.0...1.1.0
[1.0.0]: https://github.com/mattrubin/OneTimePassword/tree/1.0.0
[1.0.0]: https://github.com/mattrubin/OneTimePassword/tree/1.0.0
2 changes: 1 addition & 1 deletion OneTimePassword.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "OneTimePassword"
s.version = "2.0.0"
s.version = "2.0.1"
s.summary = "A small library for generating TOTP and HOTP one-time passwords."
s.homepage = "https://github.com/mattrubin/OneTimePassword"
s.license = "MIT"
Expand Down
8 changes: 7 additions & 1 deletion OneTimePassword.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
C94B9BCA1BD7271E0073D7C5 /* AUTHORS.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = AUTHORS.txt; sourceTree = "<group>"; };
C95B10CB196D22B9000840AA /* GeneratorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratorTests.swift; sourceTree = "<group>"; };
C95F9FB81C03D6BC00CEA286 /* PersistentToken.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistentToken.swift; sourceTree = "<group>"; };
C9619C5C1D73FB3500757587 /* .codecov.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .codecov.yml; sourceTree = "<group>"; };
C97C82381946E51D00FD9F4C /* OneTimePassword.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OneTimePassword.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C97C823C1946E51D00FD9F4C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C97C82431946E51D00FD9F4C /* OneTimePasswordTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OneTimePasswordTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -297,6 +298,7 @@
C9B84D1F1C015EC8002EE631 /* Cartfile */,
C94765061C64587800C7527E /* Cartfile.private */,
C947650A1C66ADEC00C7527E /* OneTimePassword.podspec */,
C9619C5C1D73FB3500757587 /* .codecov.yml */,
C9B84D1C1C015EC0002EE631 /* .hound.yml */,
C9B84D1D1C015EC0002EE631 /* .swiftlint.yml */,
C9B84D1E1C015EC0002EE631 /* .travis.yml */,
Expand Down Expand Up @@ -390,7 +392,7 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Matt Rubin";
TargetAttributes = {
C97C82371946E51D00FD9F4C = {
Expand Down Expand Up @@ -526,6 +528,8 @@
isa = XCBuildConfiguration;
baseConfigurationReference = C996EC2C1A74D5830076B105 /* Debug.xcconfig */;
buildSettings = {
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
Expand All @@ -540,6 +544,8 @@
isa = XCBuildConfiguration;
baseConfigurationReference = C996EC2E1A74D5830076B105 /* Release.xcconfig */;
buildSettings = {
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
GCC_NO_COMMON_BLOCKS = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
SDKROOT = iphoneos;
Expand Down
2 changes: 1 addition & 1 deletion OneTimePasswordLegacyTests/OTPToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class OTPToken: NSObject {
}
}

private convenience init(token: Token) {
fileprivate convenience init(token: Token) {
self.init()
updateWithToken(token)
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
### TOTP and HOTP one-time passwords for iOS

[![Build Status](https://travis-ci.org/mattrubin/OneTimePassword.svg?branch=master)](https://travis-ci.org/mattrubin/OneTimePassword)
[![Codecov](https://codecov.io/gh/mattrubin/OneTimePassword/branch/master/graph/badge.svg)](https://codecov.io/gh/mattrubin/OneTimePassword)
[![CocoaPods](https://img.shields.io/cocoapods/v/OneTimePassword.svg)](https://cocoapods.org/pods/OneTimePassword)
[![Carthage Compatible](https://img.shields.io/badge/carthage-%E2%9C%93-5BA7E9.svg)](https://github.com/Carthage/Carthage/)
[![MIT License](https://img.shields.io/badge/license-mit-989898.svg)](https://github.com/mattrubin/OneTimePassword/blob/master/LICENSE.md)
Expand Down
8 changes: 4 additions & 4 deletions Sources/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ import CommonCrypto
func HMAC(_ algorithm: Generator.Algorithm, key: Data, data: Data) -> Data {
let (hashFunction, hashLength) = algorithm.hashInfo

let macOut = UnsafeMutablePointer<UInt8>(allocatingCapacity: hashLength)
defer { macOut.deallocateCapacity(hashLength) }
let macOut = UnsafeMutablePointer<UInt8>.allocate(capacity: hashLength)
defer { macOut.deallocate(capacity: hashLength) }

CCHmac(hashFunction, (key as NSData).bytes, key.count, (data as NSData).bytes, data.count, macOut)

return Data(bytes: macOut, count: hashLength)
}

extension Generator.Algorithm {
private extension Generator.Algorithm {
/// The corresponding CommonCrypto hash function and hash length.
private var hashInfo: (hashFunction: CCHmacAlgorithm, hashLength: Int) {
var hashInfo: (hashFunction: CCHmacAlgorithm, hashLength: Int) {
switch self {
case .SHA1:
return (CCHmacAlgorithm(kCCHmacAlgSHA1), Int(CC_SHA1_DIGEST_LENGTH))
Expand Down
23 changes: 12 additions & 11 deletions Sources/Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Foundation

/// A `Generator` contains all of the parameters needed to generate a one-time password.
public struct Generator: Equatable {

/// The moving factor, either timer- or counter-based.
public let factor: Factor

Expand Down Expand Up @@ -78,8 +77,8 @@ public struct Generator: Equatable {
var bigCounter = counter.bigEndian

// Generate an HMAC value from the key and counter
let counterData = withUnsafePointer(&bigCounter) {
Data(bytes: UnsafePointer<UInt8>($0), count: sizeof(UInt64.self))
let counterData = withUnsafePointer(to: &bigCounter) {
Data(bytes: $0, count: MemoryLayout<UInt64>.size)
}
let hash = HMAC(algorithm, key: secret, data: counterData)

Expand All @@ -89,7 +88,9 @@ public struct Generator: Equatable {

// Take 4 bytes from the hash, starting at the given byte offset
let truncatedHashPtr = ptr + Int(offset)
let truncatedHash = UnsafePointer<UInt32>(truncatedHashPtr).pointee
let truncatedHash = truncatedHashPtr.withMemoryRebound(to: UInt32.self, capacity: 1) {
$0.pointee
}
return truncatedHash
}

Expand Down Expand Up @@ -151,7 +152,7 @@ public struct Generator: Equatable {
///
/// - throws: A `Generator.Error` if a valid counter cannot be calculated.
/// - returns: The counter value needed to generate the password for the target time.
private func counterAtTime(_ time: TimeInterval) throws -> UInt64 {
fileprivate func counterAtTime(_ time: TimeInterval) throws -> UInt64 {
switch self {
case .counter(let counter):
return counter
Expand Down Expand Up @@ -180,7 +181,7 @@ public struct Generator: Equatable {

/// An error type enum representing the various errors a `Generator` can throw when computing a
/// password.
public enum Error: ErrorProtocol {
public enum Error: Swift.Error {
/// The requested time is before the epoch date.
case invalidTime
/// The timer period is not a positive number of seconds
Expand Down Expand Up @@ -215,14 +216,14 @@ public func == (lhs: Generator.Factor, rhs: Generator.Factor) -> Bool {
private extension Generator {
// MARK: Validation

private static func validateDigits(_ digits: Int) -> Bool {
static func validateDigits(_ digits: Int) -> Bool {
// https://tools.ietf.org/html/rfc4226#section-5.3 states "Implementations MUST extract a
// 6-digit code at a minimum and possibly 7 and 8-digit codes."
let acceptableDigits = 6...8
return acceptableDigits.contains(digits)
}

private static func validateFactor(_ factor: Factor) -> Bool {
static func validateFactor(_ factor: Factor) -> Bool {
switch factor {
case .counter:
return true
Expand All @@ -231,12 +232,12 @@ private extension Generator {
}
}

private static func validatePeriod(_ period: TimeInterval) -> Bool {
static func validatePeriod(_ period: TimeInterval) -> Bool {
// The period must be positive and non-zero to produce a valid counter value.
return (period > 0)
}

private static func validateTime(_ time: TimeInterval) -> Bool {
static func validateTime(_ time: TimeInterval) -> Bool {
// The time must be positive to produce a valid counter value.
return (time >= 0)
}
Expand All @@ -248,7 +249,7 @@ private extension String {
let paddingCount = length - characters.count
guard paddingCount > 0 else { return self }

let padding = String(repeating: character, count: paddingCount)
let padding = String(repeating: String(character), count: paddingCount)
return padding + self
}
}
4 changes: 2 additions & 2 deletions Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.0</string>
<string>2.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.0.0</string>
<string>2.0.1</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
Loading