-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add support for generating Steam Guard codes #225
base: develop
Are you sure you want to change the base?
Conversation
@@ -165,6 +176,87 @@ class TokenSerializationTests: XCTestCase { | |||
} | |||
} | |||
|
|||
func testSteamGuardSerialization() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Body Length Violation: Function body should span 40 lines or less excluding comments and whitespace: currently spans 50 lines (function_body_length)
1590895162: "RFQNR", | ||
] | ||
|
||
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: .sha1, digits: 5, representation: .steamguard) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 135 characters (line_length)
let secret = MF_Base32Codec.data(fromBase32String: "I6FMHELVR57Z2PCNB7D22MS6I2SRSQIB")! | ||
let expectedValues: [TimeInterval: String] = [ | ||
1590895077: "Y4323", | ||
1590895162: "RFQNR", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing Comma Violation: Collection literals should not have trailing commas. (trailing_comma)
@@ -257,7 +263,7 @@ class GeneratorTests: XCTestCase { | |||
] | |||
|
|||
for (algorithm, expectedPasswords) in expectedValues { | |||
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: algorithm, digits: 6) | |||
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: algorithm, digits: 6, representation: .numeric) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 140 characters (line_length)
@@ -233,7 +239,7 @@ class GeneratorTests: XCTestCase { | |||
|
|||
for (algorithm, secretKey) in secretKeys { | |||
let secret = secretKey.data(using: String.Encoding.ascii)! | |||
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: algorithm, digits: 8) | |||
let generator = Generator(factor: .timer(period: 30), secret: secret, algorithm: algorithm, digits: 8, representation: .numeric) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 140 characters (line_length)
@@ -166,10 +194,11 @@ private func token(from url: URL, secret externalSecret: Data? = nil) throws -> | |||
|
|||
let algorithm = try queryItems.value(for: kQueryAlgorithmKey).map(algorithmFromString) ?? defaultAlgorithm | |||
let digits = try queryItems.value(for: kQueryDigitsKey).map(parseDigits) ?? defaultDigits | |||
let representation = try queryItems.value(for: kQueryRepresentationKey).map(representationFromString) ?? defaultRepresentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 130 characters (line_length)
} | ||
} | ||
|
||
private func urlForToken(name: String, issuer: String, factor: Generator.Factor, algorithm: Generator.Algorithm, digits: Int, representation: Generator.Representation) throws -> URL { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Parameter Count Violation: Function should have 5 parameters or less: it currently has 6 (function_parameter_count)
Line Length Violation: Line should be 120 characters or less: currently 183 characters (line_length)
} | ||
|
||
// Eventually, this throwing initializer will replace the failable initializer above. For now, the failable | ||
// initializer remains to maintain a consistent public API. Since two different initializers cannot overload the | ||
// same initializer signature with both throwing an failable versions, this new initializer is currently prefixed | ||
// with an underscore and marked as internal. | ||
internal init(_factor factor: Factor, secret: Data, algorithm: Algorithm, digits: Int) throws { | ||
internal init(_factor factor: Factor, secret: Data, algorithm: Algorithm, digits: Int, representation: Representation) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 131 characters (line_length)
public init?(factor: Factor, secret: Data, algorithm: Algorithm, digits: Int) { | ||
try? self.init(_factor: factor, secret: secret, algorithm: algorithm, digits: digits) | ||
public init?(factor: Factor, secret: Data, algorithm: Algorithm, digits: Int, representation: Representation = .numeric) { | ||
try? self.init(_factor: factor, secret: secret, algorithm: algorithm, digits: digits, representation: representation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 125 characters (line_length)
/// | ||
/// - returns: A new password generator with the given parameters, or `nil` if the parameters | ||
/// are invalid. | ||
public init?(factor: Factor, secret: Data, algorithm: Algorithm, digits: Int) { | ||
try? self.init(_factor: factor, secret: secret, algorithm: algorithm, digits: digits) | ||
public init?(factor: Factor, secret: Data, algorithm: Algorithm, digits: Int, representation: Representation = .numeric) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 126 characters (line_length)
Codecov Report
@@ Coverage Diff @@
## develop #225 +/- ##
===========================================
- Coverage 97.38% 96.95% -0.43%
===========================================
Files 6 6
Lines 420 427 +7
===========================================
+ Hits 409 414 +5
- Misses 11 13 +2
Continue to review full report at Codecov.
|
Fixes #211
Overview
Generator
named "Representation". This is an enum with two values:numeric
andsteamguard
.init(steamGuardSecret:)
). Instead, the user of the API is expected to pass the correct parameters.