Skip to content

Commit

Permalink
Release OneTimePassword 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrubin committed Feb 7, 2017
2 parents 2a82427 + d95b1dc commit 432f496
Show file tree
Hide file tree
Showing 24 changed files with 487 additions and 416 deletions.
2 changes: 1 addition & 1 deletion .hound.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration for Hound (https://houndci.com)

swift:
enabled: true
config_file: .swiftlint.yml
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3
3.0
36 changes: 32 additions & 4 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ opt_in_rules:
- conditional_returns_on_newline
- empty_count
- explicit_init
- file_header
- first_where
- missing_docs
# - missing_docs
- nimble_operator
- operator_usage_whitespace
- overridden_super_call
Expand All @@ -20,15 +21,42 @@ opt_in_rules:
- switch_case_on_newline
- vertical_whitespace
disabled_rules:
- closure_parameter_position
- colon
- comma
- cyclomatic_complexity
- function_body_length
- line_length
- syntactic_sugar
- unused_closure_parameter
- valid_docs

trailing_comma:
mandatory_comma: true

line_length:
warning: 120

file_header:
required_pattern: |
\/\/
\/\/ (.+).swift
\/\/ OneTimePassword
\/\/
\/\/ Copyright \(c\) (\d{4}|\d{4}-\d{4}) Matt Rubin and the OneTimePassword authors
\/\/
\/\/ Permission is hereby granted, free of charge, to any person obtaining a copy
\/\/ of this software and associated documentation files \(the "Software"\), to deal
\/\/ in the Software without restriction, including without limitation the rights
\/\/ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\/\/ copies of the Software, and to permit persons to whom the Software is
\/\/ furnished to do so, subject to the following conditions:
\/\/
\/\/ The above copyright notice and this permission notice shall be included in all
\/\/ copies or substantial portions of the Software.
\/\/
\/\/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\/\/ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\/\/ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\/\/ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\/\/ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\/\/ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\/\/ SOFTWARE.
\/\/
21 changes: 19 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# OneTimePassword Changelog

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

## [3.0][] (2017-02-07)
- Convert to Swift 3 and update the library API to follow the Swift [API Design Guidelines](https://swift.org/documentation/api-design-guidelines/)
([#74](https://github.com/mattrubin/OneTimePassword/pull/74),
[#78](https://github.com/mattrubin/OneTimePassword/pull/78),
[#80](https://github.com/mattrubin/OneTimePassword/pull/80),
[#91](https://github.com/mattrubin/OneTimePassword/pull/91),
[#100](https://github.com/mattrubin/OneTimePassword/pull/100),
[#111](https://github.com/mattrubin/OneTimePassword/pull/111),
[#113](https://github.com/mattrubin/OneTimePassword/pull/113),
[#122](https://github.com/mattrubin/OneTimePassword/pull/122),
[#123](https://github.com/mattrubin/OneTimePassword/pull/123),
[#125](https://github.com/mattrubin/OneTimePassword/pull/125))
- Convert `password(at:)` to take a `Date` instead of a `TimeInterval` ([#124](https://github.com/mattrubin/OneTimePassword/pull/124))
- Update the SwiftLint configuration ([#120](https://github.com/mattrubin/OneTimePassword/pull/120))


## [2.1.1][] (2016-12-28)
- Configure Travis to build and test with Xcode 8.2. ([#115](https://github.com/mattrubin/OneTimePassword/pull/115))
Expand Down Expand Up @@ -99,8 +115,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.1.1...master
[develop]: https://github.com/mattrubin/OneTimePassword/compare/3.0...develop

[3.0]: https://github.com/mattrubin/OneTimePassword/compare/2.1.1...3.0
[2.1.1]: https://github.com/mattrubin/OneTimePassword/compare/2.1...2.1.1
[2.1]: https://github.com/mattrubin/OneTimePassword/compare/2.0.1...2.1
[2.0.1]: https://github.com/mattrubin/OneTimePassword/compare/2.0.0...2.0.1
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ carthage update --no-build --use-submodules
```

[Carthage]: https://github.com/Carthage/Carthage
[Cartfile]: https://github.com/mattrubin/OneTimePassword/blob/master/Cartfile
[Cartfile]: https://github.com/mattrubin/OneTimePassword/blob/develop/Cartfile
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2016 Matt Rubin and the [OneTimePassword authors](AUTHORS.txt)
Copyright (c) 2013-2017 Matt Rubin and the [OneTimePassword authors](AUTHORS.txt)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
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.1.1"
s.version = "3.0"
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
4 changes: 2 additions & 2 deletions OneTimePassword.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@
baseConfigurationReference = C996EC2C1A74D5830076B105 /* Debug.xcconfig */;
buildSettings = {
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
name = Debug;
Expand All @@ -741,7 +741,7 @@
baseConfigurationReference = C996EC2E1A74D5830076B105 /* Release.xcconfig */;
buildSettings = {
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
name = Release;
Expand Down
86 changes: 43 additions & 43 deletions OneTimePasswordLegacyTests/OTPToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// OTPToken.swift
// OneTimePassword
//
// Copyright (c) 2013-2016 Matt Rubin and the OneTimePassword authors
// Copyright (c) 2013-2017 Matt Rubin and the OneTimePassword authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,8 +26,6 @@
import Foundation
import OneTimePassword

// swiftlint:disable missing_docs

/// `OTPToken` is a mutable, Objective-C-compatible wrapper around `OneTimePassword.Token`. For more
/// information about its properties and methods, consult the underlying `OneTimePassword`
/// documentation.
Expand All @@ -36,21 +34,21 @@ public final class OTPToken: NSObject {

public var name: String = OTPToken.defaultName
public var issuer: String = OTPToken.defaultIssuer
public var type: OTPTokenType = .Timer
public var secret: NSData = NSData()
public var type: OTPTokenType = .timer
public var secret: Data = Data()
public var algorithm: OTPAlgorithm = OTPToken.defaultAlgorithm
public var digits: UInt = OTPToken.defaultDigits
public var period: NSTimeInterval = OTPToken.defaultPeriod
public var period: TimeInterval = OTPToken.defaultPeriod
public var counter: UInt64 = OTPToken.defaultInitialCounter

private static let defaultName: String = ""
private static let defaultIssuer: String = ""
private static let defaultAlgorithm: OTPAlgorithm = .SHA1
private static let defaultAlgorithm: OTPAlgorithm = .sha1
private static var defaultDigits: UInt = 6
private static var defaultInitialCounter: UInt64 = 0
private static var defaultPeriod: NSTimeInterval = 30
private static var defaultPeriod: TimeInterval = 30

private func updateWithToken(token: Token) {
private func update(with token: Token) {
self.name = token.name
self.issuer = token.issuer

Expand All @@ -59,18 +57,18 @@ public final class OTPToken: NSObject {
self.digits = UInt(token.generator.digits)

switch token.generator.factor {
case let .Counter(counter):
self.type = .Counter
case let .counter(counter):
self.type = .counter
self.counter = counter
case let .Timer(period):
self.type = .Timer
case let .timer(period):
self.type = .timer
self.period = period
}
}

private convenience init(token: Token) {
fileprivate convenience init(token: Token) {
self.init()
updateWithToken(token)
update(with: token)
}

public func validate() -> Bool {
Expand All @@ -79,18 +77,20 @@ public final class OTPToken: NSObject {
}

public extension OTPToken {
static func tokenWithURL(url: NSURL) -> Self? {
return tokenWithURL(url, secret: nil)
@objc(tokenWithURL:)
static func token(from url: URL) -> Self? {
return token(from: url, secret: nil)
}

static func tokenWithURL(url: NSURL, secret: NSData?) -> Self? {
@objc(tokenWithURL:secret:)
static func token(from url: URL, secret: Data?) -> Self? {
guard let token = Token(url: url, secret: secret) else {
return nil
}
return self.init(token: token)
}

func url() -> NSURL? {
func url() -> URL? {
guard let token = tokenForOTPToken(self) else {
return nil
}
Expand All @@ -102,33 +102,33 @@ public extension OTPToken {

@objc
public enum OTPTokenType: UInt8 {
case Counter
case Timer
case counter
case timer
}

@objc
public enum OTPAlgorithm: UInt32 {
case SHA1
case SHA256
case SHA512
@objc(OTPAlgorithmSHA1) case sha1
@objc(OTPAlgorithmSHA256) case sha256
@objc(OTPAlgorithmSHA512) case sha512
}

// MARK: Conversion

private extension OTPAlgorithm {
init(_ generatorAlgorithm: Generator.Algorithm) {
switch generatorAlgorithm {
case .SHA1:
self = .SHA1
case .SHA256:
self = .SHA256
case .SHA512:
self = .SHA512
case .sha1:
self = .sha1
case .sha256:
self = .sha256
case .sha512:
self = .sha512
}
}
}

private func tokenForOTPToken(otpToken: OTPToken) -> Token? {
private func tokenForOTPToken(_ otpToken: OTPToken) -> Token? {
guard let generator = Generator(
factor: factorForOTPToken(otpToken),
secret: otpToken.secret,
Expand All @@ -140,22 +140,22 @@ private func tokenForOTPToken(otpToken: OTPToken) -> Token? {
return Token(name: otpToken.name, issuer: otpToken.issuer, generator: generator)
}

private func factorForOTPToken(otpToken: OTPToken) -> Generator.Factor {
private func factorForOTPToken(_ otpToken: OTPToken) -> Generator.Factor {
switch otpToken.type {
case .Counter:
return .Counter(otpToken.counter)
case .Timer:
return .Timer(period: otpToken.period)
case .counter:
return .counter(otpToken.counter)
case .timer:
return .timer(period: otpToken.period)
}
}

private func algorithmForOTPAlgorithm(algorithm: OTPAlgorithm) -> Generator.Algorithm {
private func algorithmForOTPAlgorithm(_ algorithm: OTPAlgorithm) -> Generator.Algorithm {
switch algorithm {
case .SHA1:
return .SHA1
case .SHA256:
return .SHA256
case .SHA512:
return .SHA512
case .sha1:
return .sha1
case .sha256:
return .sha256
case .sha512:
return .sha512
}
}
8 changes: 4 additions & 4 deletions OneTimePasswordLegacyTests/OTPTokenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// OTPTokenTests.swift
// OneTimePassword
//
// Copyright (c) 2015 Matt Rubin and the OneTimePassword authors
// Copyright (c) 2015-2017 Matt Rubin and the OneTimePassword authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -31,9 +31,9 @@ class OTPTokenTests: XCTestCase {

XCTAssertEqual(token.name, "")
XCTAssertEqual(token.issuer, "")
XCTAssertEqual(token.type, OTPTokenType.Timer)
XCTAssertEqual(token.secret, NSData())
XCTAssertEqual(token.algorithm, OTPAlgorithm.SHA1)
XCTAssertEqual(token.type, OTPTokenType.timer)
XCTAssertEqual(token.secret, Data())
XCTAssertEqual(token.algorithm, OTPAlgorithm.sha1)
XCTAssertEqual(token.digits, 6)
XCTAssertEqual(token.period, 30)
XCTAssertEqual(token.counter, 0)
Expand Down
Loading

0 comments on commit 432f496

Please sign in to comment.