Skip to content
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

verify(): use formatted strings instead of bytes #11

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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