PyOTP 2.2.4__py2.py3-none-any.whl → 2.2.5__py2.py3-none-any.whl

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.
pyotp/hotp.py CHANGED
@@ -5,32 +5,47 @@ from .otp import OTP
5
5
  from .compat import str
6
6
 
7
7
  class HOTP(OTP):
8
+ """
9
+ Handler for HMAC-based OTP counters.
10
+ """
8
11
  def at(self, count):
9
12
  """
10
- Generates the OTP for the given count
11
- @param [Integer] count counter
12
- @returns [Integer] OTP
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
13
19
  """
14
20
  return self.generate_otp(count)
15
21
 
16
22
  def verify(self, otp, counter):
17
23
  """
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
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
21
30
  """
22
31
  return utils.strings_equal(str(otp), str(self.at(counter)))
23
32
 
24
33
  def provisioning_uri(self, name, initial_count=0, issuer_name=None):
25
34
  """
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
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
32
46
  organization title of the OTP entry in Authenticator
33
- @return [String] provisioning uri
47
+ :returns: provisioning URI
48
+ :rtype: str
34
49
  """
35
50
  return utils.build_uri(
36
51
  self.secret,
pyotp/otp.py CHANGED
@@ -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
pyotp/totp.py CHANGED
@@ -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,
pyotp/utils.py CHANGED
@@ -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
@@ -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,6 +115,6 @@ 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/
113
119
 
114
120
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.0
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
@@ -51,7 +51,7 @@ Installation
51
51
  Usage
52
52
  -----
53
53
 
54
- Time based OTPs
54
+ Time-based OTPs
55
55
  ~~~~~~~~~~~~~~~
56
56
  ::
57
57
 
@@ -80,23 +80,29 @@ Generating a base32 Secret Key
80
80
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81
81
  ::
82
82
 
83
- pyotp.random_base32() # returns a 16 character base32 secret. Compatible with Google Authenticator
83
+ pyotp.random_base32() # returns a 16 character base32 secret. Compatible with Google Authenticator and other OTP apps
84
84
 
85
85
  Google Authenticator Compatible
86
86
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
87
 
88
- The library works with the Google Authenticator iPhone and Android app, and also includes the ability to generate
89
- provisioning URI's for use with the QR Code scanner built into the app::
88
+ PyOTP works with the Google Authenticator iPhone and Android app, as well as other OTP apps like Authy. PyOTP includes the
89
+ ability to generate provisioning URIs for use with the QR Code scanner built into these MFA client apps::
90
90
 
91
- totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/alice@google.com?secret=JBSWY3DPEHPK3PXP'
92
- hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=0'
91
+ pyotp.totp.TOTP('JBSWY3DPEHPK3PXP').provisioning_uri("alice@google.com", issuer_name="Secure App")
93
92
 
94
- This can then be rendered as a QR Code which can then be scanned and added to the users list of OTP credentials.
93
+ >>> 'otpauth://totp/Secure%20App:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Secure+App'
94
+
95
+ pyotp.hotp.HOTP('JBSWY3DPEHPK3PXP').provisioning_uri("alice@google.com", initial_count=0, issuer_name="Secure App")
96
+
97
+ >>> 'otpauth://hotp/Secure%20App:alice%40google.com?secret=JBSWY3DPEHPK3PXP&issuer=Secure+App&counter=0'
98
+
99
+ This URL can then be rendered as a QR Code (for example, using https://github.com/neocotic/qrious) which can then be scanned
100
+ and added to the users list of OTP credentials.
95
101
 
96
102
  Working example
97
103
  ~~~~~~~~~~~~~~~
98
104
 
99
- Scan the following barcode with your phone, using Google Authenticator
105
+ Scan the following barcode with your phone's OTP app (e.g. Google Authenticator):
100
106
 
101
107
  .. image:: http://chart.apis.google.com/chart?cht=qr&chs=250x250&chl=otpauth%3A%2F%2Ftotp%2Falice%40google.com%3Fsecret%3DJBSWY3DPEHPK3PXP
102
108
 
@@ -110,7 +116,7 @@ Links
110
116
  ~~~~~
111
117
 
112
118
  * `Project home page (GitHub) <https://github.com/pyotp/pyotp>`_
113
- * `Documentation (Read the Docs) <https://pyotp.readthedocs.org/en/latest/>`_
119
+ * `Documentation (Read the Docs) <https://pyotp.readthedocs.io/en/latest/>`_
114
120
  * `Package distribution (PyPI) <https://pypi.python.org/pypi/pyotp>`_
115
121
  * `Change log <https://github.com/pyotp/pyotp/blob/master/Changes.rst>`_
116
122
  * `RFC 4226: HOTP: An HMAC-Based One-Time Password <https://tools.ietf.org/html/rfc4226>`_
@@ -129,6 +135,6 @@ Links
129
135
  .. image:: https://img.shields.io/pypi/l/pyotp.svg
130
136
  :target: https://pypi.python.org/pypi/pyotp
131
137
  .. image:: https://readthedocs.org/projects/pyotp/badge/?version=latest
132
- :target: https://pyotp.readthedocs.org/
138
+ :target: https://pyotp.readthedocs.io/
133
139
 
134
140
 
@@ -0,0 +1,12 @@
1
+ pyotp/__init__.py,sha256=3I4NkdbXw4iHBbtfL7-dbNv8XZn0EUzS0Fc1riI1CJ8,485
2
+ pyotp/compat.py,sha256=QVb4buImn4PyP0qe5uLiXsO2-p4ItTGl01Vbt2dILNE,222
3
+ pyotp/hotp.py,sha256=BsY90HvawLuye4PuY7Q5DY0_HmR-83N1FVfwuw-SunI,1776
4
+ pyotp/otp.py,sha256=QPyHxZ7fY7_zlrMVVveGQrCfn6gatpaHO3-ok9XwCaU,2344
5
+ pyotp/totp.py,sha256=C734M9EaFqCFa2G0bzpJ6sW1M9bIwJj8Ib3BMuztHGE,3175
6
+ pyotp/utils.py,sha256=op4qfvo-b4sE5zFeRIOW7jhC6LXXLuODjNaEFYdZh-4,3482
7
+ pyotp-2.2.5.dist-info/DESCRIPTION.rst,sha256=FASDLIZAvjB-IGhzvwZRnNvFvh7KroZk0cvfezrj9JA,5471
8
+ pyotp-2.2.5.dist-info/METADATA,sha256=uVlep_WEqWdYGLTAo528H7ZJI-XKCgTNCM1yHMth3co,6167
9
+ pyotp-2.2.5.dist-info/RECORD,,
10
+ pyotp-2.2.5.dist-info/WHEEL,sha256=o2k-Qa-RMNIJmUdIc7KU6VWR_ErNRbWNlxDIpl7lm34,110
11
+ pyotp-2.2.5.dist-info/metadata.json,sha256=pG8Q257aEUFTs4h1opMfmDLYhP6Cl2RawF1ZFBOdY8M,825
12
+ pyotp-2.2.5.dist-info/top_level.txt,sha256=rFDgz6Sm4nbkYk6tlSRiMcJPyYdnY6LcZiAaYTxVc5k,6
@@ -1 +1 @@
1
- {"classifiers": ["Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: MacOS :: MacOS X", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules"], "extensions": {"python.details": {"contacts": [{"email": "kislyuk@gmail.com", "name": "PyOTP contributors", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/pyotp/pyotp"}}}, "generator": "bdist_wheel (0.29.0)", "license": "BSD License", "metadata_version": "2.0", "name": "pyotp", "platform": "MacOS X", "summary": "Python One Time Password Library", "version": "2.2.4"}
1
+ {"classifiers": ["Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: MacOS :: MacOS X", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules"], "extensions": {"python.details": {"contacts": [{"email": "kislyuk@gmail.com", "name": "PyOTP contributors", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/pyotp/pyotp"}}}, "generator": "bdist_wheel (0.29.0)", "license": "BSD License", "metadata_version": "2.0", "name": "pyotp", "platform": "MacOS X", "summary": "Python One Time Password Library", "version": "2.2.5"}
@@ -1,12 +0,0 @@
1
- pyotp/__init__.py,sha256=3I4NkdbXw4iHBbtfL7-dbNv8XZn0EUzS0Fc1riI1CJ8,485
2
- pyotp/compat.py,sha256=QVb4buImn4PyP0qe5uLiXsO2-p4ItTGl01Vbt2dILNE,222
3
- pyotp/hotp.py,sha256=npnuKlg4NWg5XLv2p3cMrDbtjZB24hpeQVNquFpMZdM,1467
4
- pyotp/otp.py,sha256=pyX-Rdo6AyyRAotMv-rAOQh82JtXp5tfCreIKmIq93E,2262
5
- pyotp/totp.py,sha256=2gk1cr-F3G8QBbkdSLggmKmWhEB3NqcQbhJTs6sAlvs,2561
6
- pyotp/utils.py,sha256=VTt1Dy_zR7YuhiNngYrrCmNBwroEYPpnl33rB1RO9p0,3310
7
- pyotp-2.2.4.dist-info/DESCRIPTION.rst,sha256=_DHPmEMWwU2DG7zN4cfuQp2THY2GqJnMD4SJwwx1uk4,5138
8
- pyotp-2.2.4.dist-info/METADATA,sha256=S-HdzGqhANkglB7IcKN5EYdk1Fu12bGF7xjBMxNsrgM,5834
9
- pyotp-2.2.4.dist-info/RECORD,,
10
- pyotp-2.2.4.dist-info/WHEEL,sha256=o2k-Qa-RMNIJmUdIc7KU6VWR_ErNRbWNlxDIpl7lm34,110
11
- pyotp-2.2.4.dist-info/metadata.json,sha256=0mlcDG4g6Q5r5KRX2wwT2_L7vEhqnTtg_Rh36hZld2w,825
12
- pyotp-2.2.4.dist-info/top_level.txt,sha256=rFDgz6Sm4nbkYk6tlSRiMcJPyYdnY6LcZiAaYTxVc5k,6
File without changes