PyOTP 2.2.4__tar.gz → 2.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: pyotp
3
- Version: 2.2.4
3
+ Version: 2.2.5
4
4
  Summary: Python One Time Password Library
5
5
  Home-page: https://github.com/pyotp/pyotp
6
6
  Author: PyOTP contributors
@@ -39,7 +39,7 @@ Description: PyOTP - The Python One-Time Password Library
39
39
  Usage
40
40
  -----
41
41
 
42
- Time based OTPs
42
+ Time-based OTPs
43
43
  ~~~~~~~~~~~~~~~
44
44
  ::
45
45
 
@@ -68,23 +68,29 @@ Description: PyOTP - The Python One-Time Password Library
68
68
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69
69
  ::
70
70
 
71
- pyotp.random_base32() # returns a 16 character base32 secret. Compatible with Google Authenticator
71
+ pyotp.random_base32() # returns a 16 character base32 secret. Compatible with Google Authenticator and other OTP apps
72
72
 
73
73
  Google Authenticator Compatible
74
74
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75
75
 
76
- The library works with the Google Authenticator iPhone and Android app, and also includes the ability to generate
77
- provisioning URI's for use with the QR Code scanner built into the app::
76
+ PyOTP works with the Google Authenticator iPhone and Android app, as well as other OTP apps like Authy. PyOTP includes the
77
+ ability to generate provisioning URIs for use with the QR Code scanner built into these MFA client apps::
78
78
 
79
- totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/alice@google.com?secret=JBSWY3DPEHPK3PXP'
80
- hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=0'
79
+ pyotp.totp.TOTP('JBSWY3DPEHPK3PXP').provisioning_uri("alice@google.com", issuer_name="Secure App")
81
80
 
82
- This can then be rendered as a QR Code which can then be scanned and added to the users list of OTP credentials.
81
+ >>> 'otpauth://totp/Secure%20App:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Secure+App'
82
+
83
+ pyotp.hotp.HOTP('JBSWY3DPEHPK3PXP').provisioning_uri("alice@google.com", initial_count=0, issuer_name="Secure App")
84
+
85
+ >>> 'otpauth://hotp/Secure%20App:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Secure+App&counter=0'
86
+
87
+ This URL can then be rendered as a QR Code (for example, using https://github.com/neocotic/qrious) which can then be scanned
88
+ and added to the users list of OTP credentials.
83
89
 
84
90
  Working example
85
91
  ~~~~~~~~~~~~~~~
86
92
 
87
- Scan the following barcode with your phone, using Google Authenticator
93
+ Scan the following barcode with your phone's OTP app (e.g. Google Authenticator):
88
94
 
89
95
  .. image:: http://chart.apis.google.com/chart?cht=qr&chs=250x250&chl=otpauth%3A%2F%2Ftotp%2Falice%40google.com%3Fsecret%3DJBSWY3DPEHPK3PXP
90
96
 
@@ -98,7 +104,7 @@ Description: PyOTP - The Python One-Time Password Library
98
104
  ~~~~~
99
105
 
100
106
  * `Project home page (GitHub) <https://github.com/pyotp/pyotp>`_
101
- * `Documentation (Read the Docs) <https://pyotp.readthedocs.org/en/latest/>`_
107
+ * `Documentation (Read the Docs) <https://pyotp.readthedocs.io/en/latest/>`_
102
108
  * `Package distribution (PyPI) <https://pypi.python.org/pypi/pyotp>`_
103
109
  * `Change log <https://github.com/pyotp/pyotp/blob/master/Changes.rst>`_
104
110
  * `RFC 4226: HOTP: An HMAC-Based One-Time Password <https://tools.ietf.org/html/rfc4226>`_
@@ -117,7 +123,7 @@ Description: PyOTP - The Python One-Time Password Library
117
123
  .. image:: https://img.shields.io/pypi/l/pyotp.svg
118
124
  :target: https://pypi.python.org/pypi/pyotp
119
125
  .. image:: https://readthedocs.org/projects/pyotp/badge/?version=latest
120
- :target: https://pyotp.readthedocs.org/
126
+ :target: https://pyotp.readthedocs.io/
121
127
 
122
128
  Platform: MacOS X
123
129
  Platform: Posix
@@ -31,7 +31,7 @@ Installation
31
31
  Usage
32
32
  -----
33
33
 
34
- Time based OTPs
34
+ Time-based OTPs
35
35
  ~~~~~~~~~~~~~~~
36
36
  ::
37
37
 
@@ -60,23 +60,29 @@ Generating a base32 Secret Key
60
60
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61
61
  ::
62
62
 
63
- pyotp.random_base32() # returns a 16 character base32 secret. Compatible with Google Authenticator
63
+ pyotp.random_base32() # returns a 16 character base32 secret. Compatible with Google Authenticator and other OTP apps
64
64
 
65
65
  Google Authenticator Compatible
66
66
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67
67
 
68
- The library works with the Google Authenticator iPhone and Android app, and also includes the ability to generate
69
- provisioning URI's for use with the QR Code scanner built into the app::
68
+ PyOTP works with the Google Authenticator iPhone and Android app, as well as other OTP apps like Authy. PyOTP includes the
69
+ ability to generate provisioning URIs for use with the QR Code scanner built into these MFA client apps::
70
70
 
71
- totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/alice@google.com?secret=JBSWY3DPEHPK3PXP'
72
- hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=0'
71
+ pyotp.totp.TOTP('JBSWY3DPEHPK3PXP').provisioning_uri("alice@google.com", issuer_name="Secure App")
73
72
 
74
- This can then be rendered as a QR Code which can then be scanned and added to the users list of OTP credentials.
73
+ >>> 'otpauth://totp/Secure%20App:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Secure+App'
74
+
75
+ pyotp.hotp.HOTP('JBSWY3DPEHPK3PXP').provisioning_uri("alice@google.com", initial_count=0, issuer_name="Secure App")
76
+
77
+ >>> 'otpauth://hotp/Secure%20App:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Secure+App&counter=0'
78
+
79
+ This URL can then be rendered as a QR Code (for example, using https://github.com/neocotic/qrious) which can then be scanned
80
+ and added to the users list of OTP credentials.
75
81
 
76
82
  Working example
77
83
  ~~~~~~~~~~~~~~~
78
84
 
79
- Scan the following barcode with your phone, using Google Authenticator
85
+ Scan the following barcode with your phone's OTP app (e.g. Google Authenticator):
80
86
 
81
87
  .. image:: http://chart.apis.google.com/chart?cht=qr&chs=250x250&chl=otpauth%3A%2F%2Ftotp%2Falice%40google.com%3Fsecret%3DJBSWY3DPEHPK3PXP
82
88
 
@@ -90,7 +96,7 @@ Links
90
96
  ~~~~~
91
97
 
92
98
  * `Project home page (GitHub) <https://github.com/pyotp/pyotp>`_
93
- * `Documentation (Read the Docs) <https://pyotp.readthedocs.org/en/latest/>`_
99
+ * `Documentation (Read the Docs) <https://pyotp.readthedocs.io/en/latest/>`_
94
100
  * `Package distribution (PyPI) <https://pypi.python.org/pypi/pyotp>`_
95
101
  * `Change log <https://github.com/pyotp/pyotp/blob/master/Changes.rst>`_
96
102
  * `RFC 4226: HOTP: An HMAC-Based One-Time Password <https://tools.ietf.org/html/rfc4226>`_
@@ -109,4 +115,4 @@ Links
109
115
  .. image:: https://img.shields.io/pypi/l/pyotp.svg
110
116
  :target: https://pypi.python.org/pypi/pyotp
111
117
  .. image:: https://readthedocs.org/projects/pyotp/badge/?version=latest
112
- :target: https://pyotp.readthedocs.org/
118
+ :target: https://pyotp.readthedocs.io/
@@ -8,5 +8,4 @@ ignore = E301, E302, E305, E401, E226, F841
8
8
  [egg_info]
9
9
  tag_build =
10
10
  tag_date = 0
11
- tag_svn_revision = 0
12
11
 
@@ -7,7 +7,7 @@ install_requires = [line.rstrip() for line in open(os.path.join(os.path.dirname(
7
7
 
8
8
  setup(
9
9
  name="pyotp",
10
- version="2.2.4",
10
+ version="2.2.5",
11
11
  url="https://github.com/pyotp/pyotp",
12
12
  license="BSD License",
13
13
  author="PyOTP contributors",
@@ -0,0 +1,57 @@
1
+ from __future__ import absolute_import, division, print_function, unicode_literals
2
+
3
+ from . import utils
4
+ from .otp import OTP
5
+ from .compat import str
6
+
7
+ class HOTP(OTP):
8
+ """
9
+ Handler for HMAC-based OTP counters.
10
+ """
11
+ def at(self, count):
12
+ """
13
+ Generates the OTP for the given count.
14
+
15
+ :param count: the OTP HMAC counter
16
+ :type count: int
17
+ :returns: OTP
18
+ :rtype: str
19
+ """
20
+ return self.generate_otp(count)
21
+
22
+ def verify(self, otp, counter):
23
+ """
24
+ Verifies the OTP passed in against the current time OTP.
25
+
26
+ :param otp: the OTP to check against
27
+ :type otp: str
28
+ :param count: the OTP HMAC counter
29
+ :type count: int
30
+ """
31
+ return utils.strings_equal(str(otp), str(self.at(counter)))
32
+
33
+ def provisioning_uri(self, name, initial_count=0, issuer_name=None):
34
+ """
35
+ Returns the provisioning URI for the OTP. This can then be
36
+ encoded in a QR Code and used to provision an OTP app like
37
+ Google Authenticator. See
38
+ https://github.com/google/google-authenticator/wiki/Key-Uri-Format
39
+ for more details.
40
+
41
+ :param name: name of the user account
42
+ :type name: str
43
+ :param initial_count: starting HMAC counter value, defaults to 0
44
+ :type initial_count: int
45
+ :param issuer_name: the name of the OTP issuer; this will be the
46
+ organization title of the OTP entry in Authenticator
47
+ :returns: provisioning URI
48
+ :rtype: str
49
+ """
50
+ return utils.build_uri(
51
+ self.secret,
52
+ name,
53
+ initial_count=initial_count,
54
+ issuer_name=issuer_name,
55
+ algorithm=self.digest().name,
56
+ digits=self.digits
57
+ )
@@ -6,16 +6,17 @@ import hmac
6
6
  from .compat import str
7
7
 
8
8
  class OTP(object):
9
+ """
10
+ Base class for OTP handlers.
11
+ """
9
12
  def __init__(self, s, digits=6, digest=hashlib.sha1):
10
13
  """
11
- @param [String] secret in the form of base32
12
- @option options digits [Integer] (6)
13
- Number of integers in the OTP
14
- Google Authenticate only supports 6 currently
15
- @option options digest [Callable] (hashlib.sha1)
16
- Digest used in the HMAC
17
- Google Authenticate only supports 'sha1' currently
18
- @returns [OTP] OTP instantiation
14
+ :param s: secret in base32 format
15
+ :type s: str
16
+ :param digits: number of integers in the OTP. Some apps expect this to be 6 digits, others support more.
17
+ :type digits: int
18
+ :param digest: digest function to use in the HMAC (expected to be sha1)
19
+ :type digest: callable
19
20
  """
20
21
  self.digits = digits
21
22
  self.digest = digest
@@ -23,10 +24,12 @@ class OTP(object):
23
24
 
24
25
  def generate_otp(self, input):
25
26
  """
26
- @param [Integer] input the number used seed the HMAC
27
- Usually either the counter, or the computed integer
28
- based on the Unix timestamp
27
+ :param input: the HMAC counter value to use as the OTP input.
28
+ Usually either the counter, or the computed integer based on the Unix timestamp
29
+ :type input: int
29
30
  """
31
+ if input < 0:
32
+ raise ValueError('input must be positive integer')
30
33
  hasher = hmac.new(self.byte_secret(), self.int_to_bytestring(input), self.digest)
31
34
  hmac_hash = bytearray(hasher.digest())
32
35
  offset = hmac_hash[-1] & 0xf
@@ -8,20 +8,27 @@ from .otp import OTP
8
8
  from .compat import str
9
9
 
10
10
  class TOTP(OTP):
11
+ """
12
+ Handler for time-based OTP counters.
13
+ """
11
14
  def __init__(self, *args, **kwargs):
12
15
  """
13
- @option options [Integer] interval (30) the time interval in seconds
14
- for OTP This defaults to 30 which is standard.
16
+ :param interval: the time interval in seconds
17
+ for OTP. This defaults to 30.
18
+ :type interval: int
15
19
  """
16
20
  self.interval = kwargs.pop('interval', 30)
17
21
  super(TOTP, self).__init__(*args, **kwargs)
18
22
 
19
23
  def at(self, for_time, counter_offset=0):
20
24
  """
21
- Accepts either a Unix timestamp integer or a Time object.
22
- @param [Time/Integer] time the time to generate an OTP for
23
- @param [Integer] counter_offset an amount of ticks to add to the time
24
- counter
25
+ Accepts either a Unix timestamp integer or a datetime object.
26
+
27
+ :param for_time: the time to generate an OTP for
28
+ :type for_time: int or datetime
29
+ :param counter_offset: the amount of ticks to add to the time counter
30
+ :returns: OTP value
31
+ :rtype: str
25
32
  """
26
33
  if not isinstance(for_time, datetime.datetime):
27
34
  for_time = datetime.datetime.fromtimestamp(int(for_time))
@@ -30,16 +37,24 @@ class TOTP(OTP):
30
37
  def now(self):
31
38
  """
32
39
  Generate the current time OTP
33
- @return [Integer] the OTP as an integer
40
+
41
+ :returns: OTP value
42
+ :rtype: str
34
43
  """
35
44
  return self.generate_otp(self.timecode(datetime.datetime.now()))
36
45
 
37
46
  def verify(self, otp, for_time=None, valid_window=0):
38
47
  """
39
- Verifies the OTP passed in against the current time OTP
40
- @param [String/Integer] otp the OTP to check against
41
- @param [Integer] valid_window extends the validity to this many counter
42
- ticks before and after the current one
48
+ Verifies the OTP passed in against the current time OTP.
49
+
50
+ :param otp: the OTP to check against
51
+ :type otp: str
52
+ :param for_time: Time to check OTP at (defaults to now)
53
+ :type for_time: int or datetime
54
+ :param valid_window: extends the validity to this many counter ticks before and after the current one
55
+ :type valid_window: int
56
+ :returns: True if verification succeeded, False otherwise
57
+ :rtype: bool
43
58
  """
44
59
  if for_time is None:
45
60
  for_time = datetime.datetime.now()
@@ -54,11 +69,18 @@ class TOTP(OTP):
54
69
 
55
70
  def provisioning_uri(self, name, issuer_name=None):
56
71
  """
57
- Returns the provisioning URI for the OTP
58
- This can then be encoded in a QR Code and used
59
- to provision the Google Authenticator app
60
- @param [String] name of the account
61
- @return [String] provisioning uri
72
+ Returns the provisioning URI for the OTP. This can then be
73
+ encoded in a QR Code and used to provision an OTP app like
74
+ Google Authenticator. See
75
+ https://github.com/google/google-authenticator/wiki/Key-Uri-Format
76
+ for more details.
77
+
78
+ :param name: name of the user account
79
+ :type name: str
80
+ :param issuer_name: the name of the OTP issuer; this will be the
81
+ organization title of the OTP entry in Authenticator
82
+ :returns: provisioning URI
83
+ :rtype: str
62
84
  """
63
85
  return utils.build_uri(self.secret, name, issuer_name=issuer_name,
64
86
  algorithm=self.digest().name,
@@ -25,17 +25,25 @@ def build_uri(secret, name, initial_count=None, issuer_name=None,
25
25
  See also:
26
26
  https://github.com/google/google-authenticator/wiki/Key-Uri-Format
27
27
 
28
- @param [String] the hotp/totp secret used to generate the URI
29
- @param [String] name of the account
30
- @param [Integer] initial_count starting counter value, defaults to None.
28
+ :param secret: the hotp/totp secret used to generate the URI
29
+ :type secret: str
30
+ :param name: name of the account
31
+ :type name: str
32
+ :param initial_count: starting counter value, defaults to None.
31
33
  If none, the OTP type will be assumed as TOTP.
32
- @param [String] the name of the OTP issuer; this will be the
34
+ :type initial_count: int
35
+ :param issuer_name: the name of the OTP issuer; this will be the
33
36
  organization title of the OTP entry in Authenticator
34
- @param [String] the algorithm used in the OTP generation.
35
- @param [Integer] the length of the OTP generated code.
36
- @param [Integer] the number of seconds the OTP generator is set to
37
+ :type issuer_name: str
38
+ :param algorithm: the algorithm used in the OTP generation.
39
+ :type algorithm: str
40
+ :param digits: the length of the OTP generated code.
41
+ :type digits: int
42
+ :param period: the number of seconds the OTP generator is set to
37
43
  expire every code.
38
- @return [String] provisioning uri
44
+ :type period: int
45
+ :returns: provisioning uri
46
+ :rtype: str
39
47
  """
40
48
  # initial_count may be 0 as a valid param
41
49
  is_initial_count_present = (initial_count is not None)
@@ -53,7 +61,7 @@ def build_uri(secret, name, initial_count=None, issuer_name=None,
53
61
  label = quote(name)
54
62
  if issuer_name is not None:
55
63
  label = quote(issuer_name) + ':' + label
56
- url_args['issuer'] = issuer_name
64
+ url_args['issuer'] = quote(issuer_name)
57
65
 
58
66
  if is_initial_count_present:
59
67
  url_args['counter'] = initial_count
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: pyotp
3
- Version: 2.2.4
3
+ Version: 2.2.5
4
4
  Summary: Python One Time Password Library
5
5
  Home-page: https://github.com/pyotp/pyotp
6
6
  Author: PyOTP contributors
@@ -39,7 +39,7 @@ Description: PyOTP - The Python One-Time Password Library
39
39
  Usage
40
40
  -----
41
41
 
42
- Time based OTPs
42
+ Time-based OTPs
43
43
  ~~~~~~~~~~~~~~~
44
44
  ::
45
45
 
@@ -68,23 +68,29 @@ Description: PyOTP - The Python One-Time Password Library
68
68
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69
69
  ::
70
70
 
71
- pyotp.random_base32() # returns a 16 character base32 secret. Compatible with Google Authenticator
71
+ pyotp.random_base32() # returns a 16 character base32 secret. Compatible with Google Authenticator and other OTP apps
72
72
 
73
73
  Google Authenticator Compatible
74
74
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75
75
 
76
- The library works with the Google Authenticator iPhone and Android app, and also includes the ability to generate
77
- provisioning URI's for use with the QR Code scanner built into the app::
76
+ PyOTP works with the Google Authenticator iPhone and Android app, as well as other OTP apps like Authy. PyOTP includes the
77
+ ability to generate provisioning URIs for use with the QR Code scanner built into these MFA client apps::
78
78
 
79
- totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/alice@google.com?secret=JBSWY3DPEHPK3PXP'
80
- hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=0'
79
+ pyotp.totp.TOTP('JBSWY3DPEHPK3PXP').provisioning_uri("alice@google.com", issuer_name="Secure App")
81
80
 
82
- This can then be rendered as a QR Code which can then be scanned and added to the users list of OTP credentials.
81
+ >>> 'otpauth://totp/Secure%20App:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Secure+App'
82
+
83
+ pyotp.hotp.HOTP('JBSWY3DPEHPK3PXP').provisioning_uri("alice@google.com", initial_count=0, issuer_name="Secure App")
84
+
85
+ >>> 'otpauth://hotp/Secure%20App:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Secure+App&counter=0'
86
+
87
+ This URL can then be rendered as a QR Code (for example, using https://github.com/neocotic/qrious) which can then be scanned
88
+ and added to the users list of OTP credentials.
83
89
 
84
90
  Working example
85
91
  ~~~~~~~~~~~~~~~
86
92
 
87
- Scan the following barcode with your phone, using Google Authenticator
93
+ Scan the following barcode with your phone's OTP app (e.g. Google Authenticator):
88
94
 
89
95
  .. image:: http://chart.apis.google.com/chart?cht=qr&chs=250x250&chl=otpauth%3A%2F%2Ftotp%2Falice%40google.com%3Fsecret%3DJBSWY3DPEHPK3PXP
90
96
 
@@ -98,7 +104,7 @@ Description: PyOTP - The Python One-Time Password Library
98
104
  ~~~~~
99
105
 
100
106
  * `Project home page (GitHub) <https://github.com/pyotp/pyotp>`_
101
- * `Documentation (Read the Docs) <https://pyotp.readthedocs.org/en/latest/>`_
107
+ * `Documentation (Read the Docs) <https://pyotp.readthedocs.io/en/latest/>`_
102
108
  * `Package distribution (PyPI) <https://pypi.python.org/pypi/pyotp>`_
103
109
  * `Change log <https://github.com/pyotp/pyotp/blob/master/Changes.rst>`_
104
110
  * `RFC 4226: HOTP: An HMAC-Based One-Time Password <https://tools.ietf.org/html/rfc4226>`_
@@ -117,7 +123,7 @@ Description: PyOTP - The Python One-Time Password Library
117
123
  .. image:: https://img.shields.io/pypi/l/pyotp.svg
118
124
  :target: https://pypi.python.org/pypi/pyotp
119
125
  .. image:: https://readthedocs.org/projects/pyotp/badge/?version=latest
120
- :target: https://pyotp.readthedocs.org/
126
+ :target: https://pyotp.readthedocs.io/
121
127
 
122
128
  Platform: MacOS X
123
129
  Platform: Posix
@@ -30,6 +30,11 @@ class HOTPExampleValuesFromTheRFC(unittest.TestCase):
30
30
  self.assertEqual(hotp.at(8), '399871')
31
31
  self.assertEqual(hotp.at(9), '520489')
32
32
 
33
+ def test_invalid_input(self):
34
+ hotp = pyotp.HOTP('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ')
35
+ with self.assertRaises(ValueError):
36
+ hotp.at(-1)
37
+
33
38
  def test_verify_otp_reuse(self):
34
39
  hotp = pyotp.HOTP('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ')
35
40
  self.assertTrue(hotp.verify('520489', 9))
@@ -62,7 +67,7 @@ class HOTPExampleValuesFromTheRFC(unittest.TestCase):
62
67
  self.assertEqual(url.path, '/FooCorp%21:mark%40percival')
63
68
  self.assertEqual(dict(parse_qsl(url.query)),
64
69
  {'secret': 'wrn3pqx5uqxqvnqr', 'counter': '0',
65
- 'issuer': 'FooCorp!'})
70
+ 'issuer': 'FooCorp%21'})
66
71
 
67
72
  key = 'c7uxuqhgflpw7oruedmglbrk7u6242vb'
68
73
  hotp = pyotp.HOTP(key, digits=8, digest=hashlib.sha256)
@@ -78,14 +83,14 @@ class HOTPExampleValuesFromTheRFC(unittest.TestCase):
78
83
 
79
84
  hotp = pyotp.HOTP(key, digits=8)
80
85
  url = urlparse(
81
- hotp.provisioning_uri('baco@peperina', issuer_name='FooCorp',
86
+ hotp.provisioning_uri('baco@peperina', issuer_name='Foo Corp',
82
87
  initial_count=10))
83
88
  self.assertEqual(url.scheme, 'otpauth')
84
89
  self.assertEqual(url.netloc, 'hotp')
85
- self.assertEqual(url.path, '/FooCorp:baco%40peperina')
90
+ self.assertEqual(url.path, '/Foo%20Corp:baco%40peperina')
86
91
  self.assertEqual(dict(parse_qsl(url.query)),
87
92
  {'secret': 'c7uxuqhgflpw7oruedmglbrk7u6242vb',
88
- 'counter': '10', 'issuer': 'FooCorp',
93
+ 'counter': '10', 'issuer': 'Foo%20Corp',
89
94
  'digits': '8'})
90
95
 
91
96
  def test_other_secret(self):
@@ -162,6 +167,14 @@ class TOTPExampleValuesFromTheRFC(unittest.TestCase):
162
167
  with Timecop(1297553958 + 30):
163
168
  self.assertFalse(totp.verify('102705'))
164
169
 
170
+ def test_input_before_epoch(self):
171
+ totp = pyotp.TOTP('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ')
172
+ # -1 and -29.5 round down to 0 (epoch)
173
+ self.assertEqual(totp.at(-1), '755224')
174
+ self.assertEqual(totp.at(-29.5), '755224')
175
+ with self.assertRaises(ValueError):
176
+ totp.at(-30)
177
+
165
178
  def test_validate_totp_with_digit_length(self):
166
179
  totp = pyotp.TOTP('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ')
167
180
  with Timecop(1111111111):
@@ -186,7 +199,7 @@ class TOTPExampleValuesFromTheRFC(unittest.TestCase):
186
199
  self.assertEqual(url.path, '/FooCorp%21:mark%40percival')
187
200
  self.assertEqual(dict(parse_qsl(url.query)),
188
201
  {'secret': 'wrn3pqx5uqxqvnqr',
189
- 'issuer': 'FooCorp!'})
202
+ 'issuer': 'FooCorp%21'})
190
203
 
191
204
  key = 'c7uxuqhgflpw7oruedmglbrk7u6242vb'
192
205
  totp = pyotp.TOTP(key, digits=8, interval=60, digest=hashlib.sha256)
@@ -1,42 +0,0 @@
1
- from __future__ import absolute_import, division, print_function, unicode_literals
2
-
3
- from . import utils
4
- from .otp import OTP
5
- from .compat import str
6
-
7
- class HOTP(OTP):
8
- def at(self, count):
9
- """
10
- Generates the OTP for the given count
11
- @param [Integer] count counter
12
- @returns [Integer] OTP
13
- """
14
- return self.generate_otp(count)
15
-
16
- def verify(self, otp, counter):
17
- """
18
- Verifies the OTP passed in against the current time OTP
19
- @param [String/Integer] otp the OTP to check against
20
- @param [Integer] counter the counter of the OTP
21
- """
22
- return utils.strings_equal(str(otp), str(self.at(counter)))
23
-
24
- def provisioning_uri(self, name, initial_count=0, issuer_name=None):
25
- """
26
- Returns the provisioning URI for the OTP
27
- This can then be encoded in a QR Code and used
28
- to provision the Google Authenticator app
29
- @param [String] name of the account
30
- @param [Integer] initial_count starting counter value, defaults to 0
31
- @param [String] the name of the OTP issuer; this will be the
32
- organization title of the OTP entry in Authenticator
33
- @return [String] provisioning uri
34
- """
35
- return utils.build_uri(
36
- self.secret,
37
- name,
38
- initial_count=initial_count,
39
- issuer_name=issuer_name,
40
- algorithm=self.digest().name,
41
- digits=self.digits
42
- )
File without changes
File without changes
File without changes
File without changes
File without changes