From e86dddb8f35bb0743976235bdd89bce7e6d8a773 Mon Sep 17 00:00:00 2001 From: Hsiaoming Yang Date: Thu, 20 Jul 2023 23:29:06 +0900 Subject: [PATCH] fix: use strict mypy --- pyproject.toml | 1 + src/otpauth/rfc4226.py | 5 +++-- src/otpauth/rfc6238.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 061a43a..19221f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,7 @@ exclude_lines = [ ] [tool.mypy] +strict = true python_version = "3.8" files = ["src/otpauth"] show_error_codes = true diff --git a/src/otpauth/rfc4226.py b/src/otpauth/rfc4226.py index 6967de2..86c9879 100644 --- a/src/otpauth/rfc4226.py +++ b/src/otpauth/rfc4226.py @@ -61,5 +61,6 @@ def generate_hotp(secret: bytes, counter: int, digit: int = 6, algorithm: Suppor digest = hmac.new(secret, msg, hash_alg).digest() offset = digest[19] & 0xF bin_code: int = struct.unpack(">I", digest[offset: offset + 4])[0] - base = bin_code & 0x7FFFFFFF - return base % (10**digit) + total: int = bin_code & 0x7FFFFFFF + power: int = 10 ** digit + return total % power diff --git a/src/otpauth/rfc6238.py b/src/otpauth/rfc6238.py index 661745c..04cfbbe 100644 --- a/src/otpauth/rfc6238.py +++ b/src/otpauth/rfc6238.py @@ -57,7 +57,7 @@ def generate_totp( period: int = 30, timestamp: t.Optional[int] = None, digit: int = 6, - algorithm: SupportedAlgorithms = "SHA1"): + algorithm: SupportedAlgorithms = "SHA1") -> int: """Generate a TOTP code. A TOTP code is an extension of TOTP algorithm.