From 0c3b765d82183673024d1e90dde79796f460897b Mon Sep 17 00:00:00 2001 From: Andrey Kislyuk Date: Mon, 2 Dec 2024 15:02:06 -0800 Subject: [PATCH] Format files with ruff --- src/pyotp/contrib/steam.py | 7 +------ src/pyotp/hotp.py | 5 +---- src/pyotp/otp.py | 5 +---- src/pyotp/totp.py | 5 +---- test.py | 10 ++++++++-- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/pyotp/contrib/steam.py b/src/pyotp/contrib/steam.py index 404ef81..1cd2bdd 100644 --- a/src/pyotp/contrib/steam.py +++ b/src/pyotp/contrib/steam.py @@ -13,12 +13,7 @@ class Steam(TOTP): """ def __init__( - self, - s: str, - name: Optional[str] = None, - issuer: Optional[str] = None, - interval: int = 30, - digits: int = 5 + self, s: str, name: Optional[str] = None, issuer: Optional[str] = None, interval: int = 30, digits: int = 5 ) -> None: """ :param s: secret in base32 format diff --git a/src/pyotp/hotp.py b/src/pyotp/hotp.py index 84b6e9b..c0276cf 100644 --- a/src/pyotp/hotp.py +++ b/src/pyotp/hotp.py @@ -29,10 +29,7 @@ def __init__( """ if digest is None: digest = hashlib.sha1 - elif digest in [ - hashlib.md5, - hashlib.shake_128 - ]: + elif digest in [hashlib.md5, hashlib.shake_128]: raise ValueError("selected digest function must generate digest size greater than or equals to 18 bytes") self.initial_count = initial_count diff --git a/src/pyotp/otp.py b/src/pyotp/otp.py index b339b8f..6420018 100644 --- a/src/pyotp/otp.py +++ b/src/pyotp/otp.py @@ -21,10 +21,7 @@ def __init__( if digits > 10: raise ValueError("digits must be no greater than 10") self.digest = digest - if digest in [ - hashlib.md5, - hashlib.shake_128 - ]: + if digest in [hashlib.md5, hashlib.shake_128]: raise ValueError("selected digest function must generate digest size greater than or equals to 18 bytes") self.secret = s self.name = name or "Secret" diff --git a/src/pyotp/totp.py b/src/pyotp/totp.py index ae077bc..9908d55 100644 --- a/src/pyotp/totp.py +++ b/src/pyotp/totp.py @@ -32,10 +32,7 @@ def __init__( """ if digest is None: digest = hashlib.sha1 - elif digest in [ - hashlib.md5, - hashlib.shake_128 - ]: + elif digest in [hashlib.md5, hashlib.shake_128]: raise ValueError("selected digest function must generate digest size greater than or equals to 18 bytes") self.interval = interval diff --git a/test.py b/test.py index 8c902af..2d33c60 100755 --- a/test.py +++ b/test.py @@ -334,16 +334,22 @@ def test_valid_window(self): self.assertTrue(totp.verify("681610", 200, 1)) self.assertFalse(totp.verify("195979", 200, 1)) + class DigestFunctionTest(unittest.TestCase): def test_md5(self): with self.assertRaises(ValueError) as cm: pyotp.OTP(s="secret", digest=hashlib.md5) - self.assertEqual("selected digest function must generate digest size greater than or equals to 18 bytes", str(cm.exception)) + self.assertEqual( + "selected digest function must generate digest size greater than or equals to 18 bytes", str(cm.exception) + ) def test_shake128(self): with self.assertRaises(ValueError) as cm: pyotp.OTP(s="secret", digest=hashlib.shake_128) - self.assertEqual("selected digest function must generate digest size greater than or equals to 18 bytes", str(cm.exception)) + self.assertEqual( + "selected digest function must generate digest size greater than or equals to 18 bytes", str(cm.exception) + ) + class ParseUriTest(unittest.TestCase): def test_invalids(self):