SwiftOTP icon indicating copy to clipboard operation
SwiftOTP copied to clipboard

Enforce positive numbers with UInt

Open ptrkstr opened this issue 3 years ago • 4 comments

  • generateOTP(secret: Data, algorithm: OTPAlgorithm = .sha1, counter: UInt64, digits: Int = 6) -> String was returning String? but there wasn't a way in which it could return nil
  • func generate(secondsPast1970: UInt) -> String no longer returns an optional. Positive integer is enforced via UInt usage.
  • func validateTime(time: Int) -> Bool deleted as no longer a need to validate positive integer.

ptrkstr avatar Sep 30 '21 08:09 ptrkstr

I saw your comment here @lachlanbell about UInt64 being in the spec but I couldn't see it. https://github.com/lachlanbell/SwiftOTP/issues/2#issuecomment-384644490

ptrkstr avatar Sep 30 '21 09:09 ptrkstr

Hi @ptrkstr, thanks for the PR!

Really sorry, I haven't had a chance to properly review this yet due to other commitments eating up almost all of my free time. I'll give this a proper look soon.

Regarding the spec, it mentions that the counter value C should be 8 bytes (=64 bits), so from a preliminary look I think UInt64 should still be used. The UInt64 type isn't hardware dependent, so it should work on 32-bit systems as well.

lachlanbell avatar Oct 04 '21 15:10 lachlanbell

Hey @lachlanbell, Thanks for the reply, no apology necessary :) Ahh great point, let me revert the UInt64 changes. I think there's value in the other changes I've made regarding UInt over Int to avoid a guard for negative number checking. I'll comment back when it's done.

ptrkstr avatar Oct 04 '21 19:10 ptrkstr

Hey @lachlanbell, I've reverted the UInt64 changes, ready for review.

ptrkstr avatar Oct 05 '21 16:10 ptrkstr