From b650e356cb930ef7aa1925fee7c2205fc199bbc4 Mon Sep 17 00:00:00 2001 From: Andrey Kislyuk Date: Fri, 25 Oct 2019 08:59:01 -0700 Subject: [PATCH] Test and lint config updates --- setup.cfg | 2 +- src/pyotp/__init__.py | 2 ++ src/pyotp/hotp.py | 1 + src/pyotp/otp.py | 1 + src/pyotp/totp.py | 1 + test.py | 8 ++++++++ 6 files changed, 14 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index a531509..f0daf66 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,4 +2,4 @@ universal=1 [flake8] max-line-length=120 -ignore: E301, E302, W504 +ignore: E401, W504 diff --git a/src/pyotp/__init__.py b/src/pyotp/__init__.py index 80f5218..cd1330c 100644 --- a/src/pyotp/__init__.py +++ b/src/pyotp/__init__.py @@ -6,6 +6,7 @@ from pyotp.totp import TOTP # noqa from . import utils # noqa + def random_base32(length=16, random=None, chars=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')): if length < 16: @@ -23,6 +24,7 @@ def random_base32(length=16, random=None, for _ in range(length) ) + def random_hex(length=32, random=None, chars=list('ABCDEF0123456789')): if length < 32: diff --git a/src/pyotp/hotp.py b/src/pyotp/hotp.py index bb9e3f1..2b3cfa8 100644 --- a/src/pyotp/hotp.py +++ b/src/pyotp/hotp.py @@ -4,6 +4,7 @@ from .otp import OTP from .compat import str + class HOTP(OTP): """ Handler for HMAC-based OTP counters. diff --git a/src/pyotp/otp.py b/src/pyotp/otp.py index 45afcf3..632b7d3 100644 --- a/src/pyotp/otp.py +++ b/src/pyotp/otp.py @@ -5,6 +5,7 @@ import hmac from .compat import str + class OTP(object): """ Base class for OTP handlers. diff --git a/src/pyotp/totp.py b/src/pyotp/totp.py index 50faf8b..46fd43b 100644 --- a/src/pyotp/totp.py +++ b/src/pyotp/totp.py @@ -7,6 +7,7 @@ from .otp import OTP from .compat import str + class TOTP(OTP): """ Handler for time-based OTP counters. diff --git a/test.py b/test.py index ab5cab2..d05e801 100755 --- a/test.py +++ b/test.py @@ -14,6 +14,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) import pyotp # noqa + class HOTPExampleValuesFromTheRFC(unittest.TestCase): def test_match_rfc(self): # 12345678901234567890 in Bas32 @@ -236,6 +237,12 @@ def test_provisioning_uri(self): def test_random_key_generation(self): self.assertEqual(len(pyotp.random_base32()), 16) self.assertEqual(len(pyotp.random_base32(length=20)), 20) + self.assertEqual(len(pyotp.random_hex()), 32) + self.assertEqual(len(pyotp.random_hex(length=64)), 64) + with self.assertRaises(Exception): + pyotp.random_base32(length=15) + with self.assertRaises(Exception): + pyotp.random_hex(length=24) class CompareDigestTest(unittest.TestCase): @@ -305,5 +312,6 @@ def now(cls, **kwargs): timecop = self return FrozenDateTime + if __name__ == '__main__': unittest.main()