From f2d28d0a83891ebf7d81fc70935954165bdcffa8 Mon Sep 17 00:00:00 2001 From: Genaro Camele Date: Mon, 10 Mar 2025 22:24:02 -0300 Subject: [PATCH] Improved generate_otp() performance in Steam class --- src/pyotp/contrib/steam.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pyotp/contrib/steam.py b/src/pyotp/contrib/steam.py index 1cd2bdd..35c6cc6 100644 --- a/src/pyotp/contrib/steam.py +++ b/src/pyotp/contrib/steam.py @@ -29,16 +29,12 @@ def generate_otp(self, input: int) -> str: :param input: the HMAC counter value to use as the OTP input. Usually either the counter, or the computed integer based on the Unix timestamp """ - str_code = super().generate_otp(input) - int_code = int(str_code) - - steam_code = "" + int_code = int(super().generate_otp(input)) total_chars = len(STEAM_CHARS) + digits = [] for _ in range(STEAM_DEFAULT_DIGITS): - pos = int_code % total_chars - char = STEAM_CHARS[int(pos)] - steam_code += char + digits.append(STEAM_CHARS[int_code % total_chars]) int_code //= total_chars - return steam_code + return "".join(digits)