Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliopavia committed Apr 22, 2024
1 parent 17183c2 commit 8b745be
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Guardian/Generators/OneTimePasswordGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ struct OneTimePasswordGenerator: TOTP, HOTP {
var c = UInt64(counter).bigEndian
let buffer = Data(bytes: &c, count: MemoryLayout<UInt64>.size);
let digestData = hmac.sign(buffer)
let length = MemoryLayout<UInt32>.size
guard let offset = digestData.last.map({ Int($0 & 0x0f) }),
(offset + 4) < digestData.count else {
return -1
(offset + length) < digestData.count else {
return 0

Check warning on line 88 in Guardian/Generators/OneTimePasswordGenerator.swift

View check run for this annotation

Codecov / codecov/patch

Guardian/Generators/OneTimePasswordGenerator.swift#L88

Added line #L88 was not covered by tests
}
var hash = digestData.dropFirst(offset).prefix(4).reduce(0, { $0 << 8 | UInt32($1) })
var hash = digestData.dropFirst(offset).prefix(length).reduce(0, { $0 << 8 | UInt32($1) })
hash &= 0x7fffffff
hash = hash % UInt32(pow(10, Float(self.parameters.digits)))
return Int(hash)
Expand Down

0 comments on commit 8b745be

Please sign in to comment.