Skip to content

Commit

Permalink
Format files with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Dec 2, 2024
1 parent a398c80 commit 0c3b765
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
7 changes: 1 addition & 6 deletions src/pyotp/contrib/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/pyotp/hotp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/pyotp/otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions src/pyotp/totp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0c3b765

Please sign in to comment.