Skip to content

Commit 432f496

Browse files
committed
Release OneTimePassword 3.0
2 parents 2a82427 + d95b1dc commit 432f496

24 files changed

+487
-416
lines changed

.hound.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Configuration for Hound (https://houndci.com)
22

33
swift:
4-
enabled: true
4+
config_file: .swiftlint.yml

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3
1+
3.0

.swiftlint.yml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ opt_in_rules:
99
- conditional_returns_on_newline
1010
- empty_count
1111
- explicit_init
12+
- file_header
1213
- first_where
13-
- missing_docs
14+
# - missing_docs
1415
- nimble_operator
1516
- operator_usage_whitespace
1617
- overridden_super_call
@@ -20,15 +21,42 @@ opt_in_rules:
2021
- switch_case_on_newline
2122
- vertical_whitespace
2223
disabled_rules:
23-
- closure_parameter_position
2424
- colon
2525
- comma
2626
- cyclomatic_complexity
2727
- function_body_length
28-
- line_length
2928
- syntactic_sugar
30-
- unused_closure_parameter
3129
- valid_docs
3230

3331
trailing_comma:
3432
mandatory_comma: true
33+
34+
line_length:
35+
warning: 120
36+
37+
file_header:
38+
required_pattern: |
39+
\/\/
40+
\/\/ (.+).swift
41+
\/\/ OneTimePassword
42+
\/\/
43+
\/\/ Copyright \(c\) (\d{4}|\d{4}-\d{4}) Matt Rubin and the OneTimePassword authors
44+
\/\/
45+
\/\/ Permission is hereby granted, free of charge, to any person obtaining a copy
46+
\/\/ of this software and associated documentation files \(the "Software"\), to deal
47+
\/\/ in the Software without restriction, including without limitation the rights
48+
\/\/ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49+
\/\/ copies of the Software, and to permit persons to whom the Software is
50+
\/\/ furnished to do so, subject to the following conditions:
51+
\/\/
52+
\/\/ The above copyright notice and this permission notice shall be included in all
53+
\/\/ copies or substantial portions of the Software.
54+
\/\/
55+
\/\/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56+
\/\/ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57+
\/\/ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58+
\/\/ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59+
\/\/ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60+
\/\/ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61+
\/\/ SOFTWARE.
62+
\/\/

CHANGELOG.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# OneTimePassword Changelog
22

3-
<!--## [In development][master]-->
3+
<!--## [In development][develop]-->
4+
5+
## [3.0][] (2017-02-07)
6+
- Convert to Swift 3 and update the library API to follow the Swift [API Design Guidelines](https://swift.org/documentation/api-design-guidelines/)
7+
([#74](https://github.com/mattrubin/OneTimePassword/pull/74),
8+
[#78](https://github.com/mattrubin/OneTimePassword/pull/78),
9+
[#80](https://github.com/mattrubin/OneTimePassword/pull/80),
10+
[#91](https://github.com/mattrubin/OneTimePassword/pull/91),
11+
[#100](https://github.com/mattrubin/OneTimePassword/pull/100),
12+
[#111](https://github.com/mattrubin/OneTimePassword/pull/111),
13+
[#113](https://github.com/mattrubin/OneTimePassword/pull/113),
14+
[#122](https://github.com/mattrubin/OneTimePassword/pull/122),
15+
[#123](https://github.com/mattrubin/OneTimePassword/pull/123),
16+
[#125](https://github.com/mattrubin/OneTimePassword/pull/125))
17+
- Convert `password(at:)` to take a `Date` instead of a `TimeInterval` ([#124](https://github.com/mattrubin/OneTimePassword/pull/124))
18+
- Update the SwiftLint configuration ([#120](https://github.com/mattrubin/OneTimePassword/pull/120))
19+
420

521
## [2.1.1][] (2016-12-28)
622
- Configure Travis to build and test with Xcode 8.2. ([#115](https://github.com/mattrubin/OneTimePassword/pull/115))
@@ -99,8 +115,9 @@ Changes between prerelease versions of OneTimePassword version 2 can be found be
99115

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

102-
[master]: https://github.com/mattrubin/OneTimePassword/compare/2.1.1...master
118+
[develop]: https://github.com/mattrubin/OneTimePassword/compare/3.0...develop
103119

120+
[3.0]: https://github.com/mattrubin/OneTimePassword/compare/2.1.1...3.0
104121
[2.1.1]: https://github.com/mattrubin/OneTimePassword/compare/2.1...2.1.1
105122
[2.1]: https://github.com/mattrubin/OneTimePassword/compare/2.0.1...2.1
106123
[2.0.1]: https://github.com/mattrubin/OneTimePassword/compare/2.0.0...2.0.1

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ carthage update --no-build --use-submodules
4747
```
4848

4949
[Carthage]: https://github.com/Carthage/Carthage
50-
[Cartfile]: https://github.com/mattrubin/OneTimePassword/blob/master/Cartfile
50+
[Cartfile]: https://github.com/mattrubin/OneTimePassword/blob/develop/Cartfile

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

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

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

OneTimePassword.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "OneTimePassword"
3-
s.version = "2.1.1"
3+
s.version = "3.0"
44
s.summary = "A small library for generating TOTP and HOTP one-time passwords."
55
s.homepage = "https://github.com/mattrubin/OneTimePassword"
66
s.license = "MIT"

OneTimePassword.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@
731731
baseConfigurationReference = C996EC2C1A74D5830076B105 /* Debug.xcconfig */;
732732
buildSettings = {
733733
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
734-
SWIFT_VERSION = 2.3;
734+
SWIFT_VERSION = 3.0;
735735
WATCHOS_DEPLOYMENT_TARGET = 2.0;
736736
};
737737
name = Debug;
@@ -741,7 +741,7 @@
741741
baseConfigurationReference = C996EC2E1A74D5830076B105 /* Release.xcconfig */;
742742
buildSettings = {
743743
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
744-
SWIFT_VERSION = 2.3;
744+
SWIFT_VERSION = 3.0;
745745
WATCHOS_DEPLOYMENT_TARGET = 2.0;
746746
};
747747
name = Release;

OneTimePasswordLegacyTests/OTPToken.swift

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// OTPToken.swift
33
// OneTimePassword
44
//
5-
// Copyright (c) 2013-2016 Matt Rubin and the OneTimePassword authors
5+
// Copyright (c) 2013-2017 Matt Rubin and the OneTimePassword authors
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
@@ -26,8 +26,6 @@
2626
import Foundation
2727
import OneTimePassword
2828

29-
// swiftlint:disable missing_docs
30-
3129
/// `OTPToken` is a mutable, Objective-C-compatible wrapper around `OneTimePassword.Token`. For more
3230
/// information about its properties and methods, consult the underlying `OneTimePassword`
3331
/// documentation.
@@ -36,21 +34,21 @@ public final class OTPToken: NSObject {
3634

3735
public var name: String = OTPToken.defaultName
3836
public var issuer: String = OTPToken.defaultIssuer
39-
public var type: OTPTokenType = .Timer
40-
public var secret: NSData = NSData()
37+
public var type: OTPTokenType = .timer
38+
public var secret: Data = Data()
4139
public var algorithm: OTPAlgorithm = OTPToken.defaultAlgorithm
4240
public var digits: UInt = OTPToken.defaultDigits
43-
public var period: NSTimeInterval = OTPToken.defaultPeriod
41+
public var period: TimeInterval = OTPToken.defaultPeriod
4442
public var counter: UInt64 = OTPToken.defaultInitialCounter
4543

4644
private static let defaultName: String = ""
4745
private static let defaultIssuer: String = ""
48-
private static let defaultAlgorithm: OTPAlgorithm = .SHA1
46+
private static let defaultAlgorithm: OTPAlgorithm = .sha1
4947
private static var defaultDigits: UInt = 6
5048
private static var defaultInitialCounter: UInt64 = 0
51-
private static var defaultPeriod: NSTimeInterval = 30
49+
private static var defaultPeriod: TimeInterval = 30
5250

53-
private func updateWithToken(token: Token) {
51+
private func update(with token: Token) {
5452
self.name = token.name
5553
self.issuer = token.issuer
5654

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

6159
switch token.generator.factor {
62-
case let .Counter(counter):
63-
self.type = .Counter
60+
case let .counter(counter):
61+
self.type = .counter
6462
self.counter = counter
65-
case let .Timer(period):
66-
self.type = .Timer
63+
case let .timer(period):
64+
self.type = .timer
6765
self.period = period
6866
}
6967
}
7068

71-
private convenience init(token: Token) {
69+
fileprivate convenience init(token: Token) {
7270
self.init()
73-
updateWithToken(token)
71+
update(with: token)
7472
}
7573

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

8179
public extension OTPToken {
82-
static func tokenWithURL(url: NSURL) -> Self? {
83-
return tokenWithURL(url, secret: nil)
80+
@objc(tokenWithURL:)
81+
static func token(from url: URL) -> Self? {
82+
return token(from: url, secret: nil)
8483
}
8584

86-
static func tokenWithURL(url: NSURL, secret: NSData?) -> Self? {
85+
@objc(tokenWithURL:secret:)
86+
static func token(from url: URL, secret: Data?) -> Self? {
8787
guard let token = Token(url: url, secret: secret) else {
8888
return nil
8989
}
9090
return self.init(token: token)
9191
}
9292

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

103103
@objc
104104
public enum OTPTokenType: UInt8 {
105-
case Counter
106-
case Timer
105+
case counter
106+
case timer
107107
}
108108

109109
@objc
110110
public enum OTPAlgorithm: UInt32 {
111-
case SHA1
112-
case SHA256
113-
case SHA512
111+
@objc(OTPAlgorithmSHA1) case sha1
112+
@objc(OTPAlgorithmSHA256) case sha256
113+
@objc(OTPAlgorithmSHA512) case sha512
114114
}
115115

116116
// MARK: Conversion
117117

118118
private extension OTPAlgorithm {
119119
init(_ generatorAlgorithm: Generator.Algorithm) {
120120
switch generatorAlgorithm {
121-
case .SHA1:
122-
self = .SHA1
123-
case .SHA256:
124-
self = .SHA256
125-
case .SHA512:
126-
self = .SHA512
121+
case .sha1:
122+
self = .sha1
123+
case .sha256:
124+
self = .sha256
125+
case .sha512:
126+
self = .sha512
127127
}
128128
}
129129
}
130130

131-
private func tokenForOTPToken(otpToken: OTPToken) -> Token? {
131+
private func tokenForOTPToken(_ otpToken: OTPToken) -> Token? {
132132
guard let generator = Generator(
133133
factor: factorForOTPToken(otpToken),
134134
secret: otpToken.secret,
@@ -140,22 +140,22 @@ private func tokenForOTPToken(otpToken: OTPToken) -> Token? {
140140
return Token(name: otpToken.name, issuer: otpToken.issuer, generator: generator)
141141
}
142142

143-
private func factorForOTPToken(otpToken: OTPToken) -> Generator.Factor {
143+
private func factorForOTPToken(_ otpToken: OTPToken) -> Generator.Factor {
144144
switch otpToken.type {
145-
case .Counter:
146-
return .Counter(otpToken.counter)
147-
case .Timer:
148-
return .Timer(period: otpToken.period)
145+
case .counter:
146+
return .counter(otpToken.counter)
147+
case .timer:
148+
return .timer(period: otpToken.period)
149149
}
150150
}
151151

152-
private func algorithmForOTPAlgorithm(algorithm: OTPAlgorithm) -> Generator.Algorithm {
152+
private func algorithmForOTPAlgorithm(_ algorithm: OTPAlgorithm) -> Generator.Algorithm {
153153
switch algorithm {
154-
case .SHA1:
155-
return .SHA1
156-
case .SHA256:
157-
return .SHA256
158-
case .SHA512:
159-
return .SHA512
154+
case .sha1:
155+
return .sha1
156+
case .sha256:
157+
return .sha256
158+
case .sha512:
159+
return .sha512
160160
}
161161
}

OneTimePasswordLegacyTests/OTPTokenTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// OTPTokenTests.swift
33
// OneTimePassword
44
//
5-
// Copyright (c) 2015 Matt Rubin and the OneTimePassword authors
5+
// Copyright (c) 2015-2017 Matt Rubin and the OneTimePassword authors
66
//
77
// Permission is hereby granted, free of charge, to any person obtaining a copy
88
// of this software and associated documentation files (the "Software"), to deal
@@ -31,9 +31,9 @@ class OTPTokenTests: XCTestCase {
3131

3232
XCTAssertEqual(token.name, "")
3333
XCTAssertEqual(token.issuer, "")
34-
XCTAssertEqual(token.type, OTPTokenType.Timer)
35-
XCTAssertEqual(token.secret, NSData())
36-
XCTAssertEqual(token.algorithm, OTPAlgorithm.SHA1)
34+
XCTAssertEqual(token.type, OTPTokenType.timer)
35+
XCTAssertEqual(token.secret, Data())
36+
XCTAssertEqual(token.algorithm, OTPAlgorithm.sha1)
3737
XCTAssertEqual(token.digits, 6)
3838
XCTAssertEqual(token.period, 30)
3939
XCTAssertEqual(token.counter, 0)

0 commit comments

Comments
 (0)