PyOTP 1.3.1__tar.gz → 1.4__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.0
2
2
  Name: pyotp
3
- Version: 1.3.1
3
+ Version: 1.4
4
4
  Summary: https://github.com/nathforge/pyotp
5
5
  Home-page: https://github.com/nathforge/pyotp
6
6
  Author: Mark Percival (ported by Nathan Reynolds to Python)
@@ -3,7 +3,7 @@
3
3
  from distutils.core import setup
4
4
 
5
5
  setup(
6
- version='1.3.1',
6
+ version='1.4',
7
7
  url='https://github.com/nathforge/pyotp',
8
8
  name='pyotp',
9
9
  description='https://github.com/nathforge/pyotp',
@@ -10,15 +10,15 @@ class HOTP(OTP):
10
10
  @returns [Integer] OTP
11
11
  """
12
12
  return self.generate_otp(count)
13
-
13
+
14
14
  def verify(self, otp, counter):
15
15
  """
16
16
  Verifies the OTP passed in against the current time OTP
17
17
  @param [String/Integer] otp the OTP to check against
18
18
  @param [Integer] counter the counter of the OTP
19
19
  """
20
- return otp == self.at(counter)
21
-
20
+ return unicode(otp) == unicode(self.at(counter))
21
+
22
22
  def provisioning_uri(self, name, initial_count=0):
23
23
  """
24
24
  Returns the provisioning URI for the OTP
@@ -7,12 +7,12 @@ import urllib
7
7
  class TOTP(OTP):
8
8
  def __init__(self, *args, **kwargs):
9
9
  """
10
- @option options [Integer] interval (30) the time interval in seconds for OTP
11
- This defaults to 30 which is standard.
10
+ @option options [Integer] interval (30) the time interval in seconds
11
+ for OTP This defaults to 30 which is standard.
12
12
  """
13
13
  self.interval = kwargs.pop('interval', 30)
14
14
  super(TOTP, self).__init__(*args, **kwargs)
15
-
15
+
16
16
  def at(self, for_time):
17
17
  """
18
18
  Accepts either a Unix timestamp integer or a Time object.
@@ -22,14 +22,14 @@ class TOTP(OTP):
22
22
  if not isinstance(for_time, datetime.datetime):
23
23
  for_time = datetime.datetime.fromtimestamp(int(for_time))
24
24
  return self.generate_otp(self.timecode(for_time))
25
-
25
+
26
26
  def now(self):
27
27
  """
28
28
  Generate the current time OTP
29
29
  @return [Integer] the OTP as an integer
30
30
  """
31
31
  return self.generate_otp(self.timecode(datetime.datetime.now()))
32
-
32
+
33
33
  def verify(self, otp, for_time=None):
34
34
  """
35
35
  Verifies the OTP passed in against the current time OTP
@@ -37,8 +37,9 @@ class TOTP(OTP):
37
37
  """
38
38
  if for_time is None:
39
39
  for_time = datetime.datetime.now()
40
- return otp == self.at(for_time)
41
-
40
+
41
+ return unicode(otp) == unicode(self.at(for_time))
42
+
42
43
  def provisioning_uri(self, name):
43
44
  """
44
45
  Returns the provisioning URI for the OTP
@@ -51,7 +52,7 @@ class TOTP(OTP):
51
52
  'name': urllib.quote(name, safe='@'),
52
53
  'secret': self.secret,
53
54
  }
54
-
55
+
55
56
  def timecode(self, for_time):
56
57
  i = time.mktime(for_time.timetuple())
57
58
  return int(i / self.interval)
@@ -23,12 +23,13 @@ class HOTPExampleValuesFromTheRFC(unittest.TestCase):
23
23
  self.assertEqual(hotp.at(7), 162583)
24
24
  self.assertEqual(hotp.at(8), 399871)
25
25
  self.assertEqual(hotp.at(9), 520489)
26
-
26
+
27
27
  def testVerifyAnOTPAndNowAllowReuse(self):
28
28
  hotp = pyotp.HOTP('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ')
29
29
  self.assertTrue(hotp.verify(520489, 9))
30
30
  self.assertFalse(hotp.verify(520489, 10))
31
-
31
+ self.assertFalse(hotp.verify("520489", 10))
32
+
32
33
  def testProvisioningURI(self):
33
34
  hotp = pyotp.HOTP('wrn3pqx5uqxqvnqr')
34
35
  self.assertEqual(hotp.provisioning_uri('mark@percival'), 'otpauth://hotp/mark@percival?secret=wrn3pqx5uqxqvnqr&counter=0')
@@ -40,19 +41,20 @@ class TOTPExampleValuesFromTheRFC(unittest.TestCase):
40
41
  self.assertEqual(totp.at(1111111111), 50471)
41
42
  self.assertEqual(totp.at(1234567890), 5924)
42
43
  self.assertEqual(totp.at(2000000000), 279037)
43
-
44
+
44
45
  def testMatchTheGoogleAuthenticatorOutput(self):
45
46
  totp = pyotp.TOTP('wrn3pqx5uqxqvnqr')
46
47
  with Timecop(1297553958):
47
48
  self.assertEqual(totp.now(), 102705)
48
-
49
+
49
50
  def testValidateATimeBasedOTP(self):
50
51
  totp = pyotp.TOTP('wrn3pqx5uqxqvnqr')
51
52
  with Timecop(1297553958):
52
53
  self.assertTrue(totp.verify(102705))
54
+ self.assertTrue(totp.verify("102705"))
53
55
  with Timecop(1297553958 + 30):
54
56
  self.assertFalse(totp.verify(102705))
55
-
57
+
56
58
  def testProvisioningURI(self):
57
59
  totp = pyotp.TOTP('wrn3pqx5uqxqvnqr')
58
60
  self.assertEqual(totp.provisioning_uri('mark@percival'), 'otpauth://totp/mark@percival?secret=wrn3pqx5uqxqvnqr')
@@ -62,23 +64,23 @@ class Timecop(object):
62
64
  """
63
65
  Half-assed clone of timecop.rb, just enough to pass our tests.
64
66
  """
65
-
67
+
66
68
  def __init__(self, freeze_timestamp):
67
69
  self.freeze_timestamp = freeze_timestamp
68
-
70
+
69
71
  def __enter__(self):
70
72
  self.real_datetime = datetime.datetime
71
73
  datetime.datetime = self.frozen_datetime()
72
-
74
+
73
75
  def __exit__(self, type, value, traceback):
74
76
  datetime.datetime = self.real_datetime
75
-
77
+
76
78
  def frozen_datetime(self):
77
79
  class FrozenDateTime(datetime.datetime):
78
80
  @classmethod
79
81
  def now(cls):
80
82
  return cls.fromtimestamp(timecop.freeze_timestamp)
81
-
83
+
82
84
  timecop = self
83
85
  return FrozenDateTime
84
86
 
File without changes
File without changes
File without changes
File without changes