Skip to content

Commit

Permalink
Merge pull request #11 from joergschulz/master
Browse files Browse the repository at this point in the history
verify(): use formatted strings instead of bytes
  • Loading branch information
lepture authored Sep 9, 2023
2 parents 22368eb + 73ca0f3 commit b0847d4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/otpauth/rfc4226.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def verify(self, code: int, counter: int) -> bool: # type: ignore[override]
"""
if len(str(code)) > self.digit:
return False
return hmac.compare_digest(bytes(self.generate(counter)), bytes(code))
return hmac.compare_digest(f'{self.generate(counter):0{self.digit}}', f'{code:0{self.digit}}')

def to_uri(self, label: str, issuer: str, counter: int) -> str: # type: ignore[override]
"""Generate the otpauth protocal string for HOTP.
Expand Down
2 changes: 1 addition & 1 deletion src/otpauth/rfc6238.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def verify(self, code: int, timestamp: t.Optional[int] = None) -> bool: # type:
"""
if len(str(code)) > self.digit:
return False
return hmac.compare_digest(bytes(self.generate(timestamp)), bytes(code))
return hmac.compare_digest(f'{self.generate(timestamp):0{self.digit}}', f'{code:0{self.digit}}')

def to_uri(self, label: str, issuer: str) -> str: # type: ignore[override]
"""Generate the otpauth protocal string for TOTP.
Expand Down

0 comments on commit b0847d4

Please sign in to comment.