aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiangge Zhang <tonyseek@gmail.com>2015-06-03 17:30:11 +0800
committerJiangge Zhang <tonyseek@gmail.com>2015-06-03 17:39:59 +0800
commitd4e0a839ef676a2ed05140f98ef3630deb0fdd61 (patch)
tree4786265848ce18dbda22f6daa3b3a28e6c48d561
parente9f8eb9af0c4f42dd4e68ae05580f77dc352aaf4 (diff)
downloadcryptography-d4e0a839ef676a2ed05140f98ef3630deb0fdd61.tar.gz
cryptography-d4e0a839ef676a2ed05140f98ef3630deb0fdd61.tar.bz2
cryptography-d4e0a839ef676a2ed05140f98ef3630deb0fdd61.zip
Remove a default argument and rename a private function.
-rw-r--r--docs/hazmat/primitives/twofactor.rst10
-rw-r--r--src/cryptography/hazmat/primitives/twofactor/hotp.py6
-rw-r--r--src/cryptography/hazmat/primitives/twofactor/totp.py6
-rw-r--r--src/cryptography/hazmat/primitives/twofactor/utils.py4
-rw-r--r--tests/hazmat/primitives/twofactor/test_hotp.py4
-rw-r--r--tests/hazmat/primitives/twofactor/test_totp.py2
6 files changed, 17 insertions, 15 deletions
diff --git a/docs/hazmat/primitives/twofactor.rst b/docs/hazmat/primitives/twofactor.rst
index dace6f7d..016c30eb 100644
--- a/docs/hazmat/primitives/twofactor.rst
+++ b/docs/hazmat/primitives/twofactor.rst
@@ -74,11 +74,12 @@ codes (HMAC).
:raises cryptography.hazmat.primitives.twofactor.InvalidToken: This
is raised when the supplied HOTP does not match the expected HOTP.
- .. method:: get_provisioning_uri(account_name, counter, issuer=None)
+ .. method:: get_provisioning_uri(account_name, counter, issuer)
:param str account_name: The display name of account, such as
``'Alice Smith'`` or ``'alice@example.com'``.
- :param str issuer: The optional display name of issuer.
+ :param issuer: The optional display name of issuer.
+ :type issuer: `string` or `None`
:param int counter: The current value of counter.
:return str: An URI string.
@@ -180,11 +181,12 @@ similar to the following code.
:raises cryptography.hazmat.primitives.twofactor.InvalidToken: This
is raised when the supplied TOTP does not match the expected TOTP.
- .. method:: get_provisioning_uri(account_name, issuer=None)
+ .. method:: get_provisioning_uri(account_name, issuer)
:param str account_name: The display name of account, such as
``'Alice Smith'`` or ``'alice@example.com'``.
- :param str issuer: The optional display name of issuer.
+ :param issuer: The optional display name of issuer.
+ :type issuer: `string` or `None`
:return str: An URI string.
Provisioning URI
diff --git a/src/cryptography/hazmat/primitives/twofactor/hotp.py b/src/cryptography/hazmat/primitives/twofactor/hotp.py
index f59f551c..8c0cec14 100644
--- a/src/cryptography/hazmat/primitives/twofactor/hotp.py
+++ b/src/cryptography/hazmat/primitives/twofactor/hotp.py
@@ -15,7 +15,7 @@ from cryptography.hazmat.backends.interfaces import HMACBackend
from cryptography.hazmat.primitives import constant_time, hmac
from cryptography.hazmat.primitives.hashes import SHA1, SHA256, SHA512
from cryptography.hazmat.primitives.twofactor import InvalidToken
-from cryptography.hazmat.primitives.twofactor.utils import generate_uri
+from cryptography.hazmat.primitives.twofactor.utils import _generate_uri
class HOTP(object):
@@ -61,7 +61,7 @@ class HOTP(object):
p = hmac_value[offset:offset + 4]
return struct.unpack(">I", p)[0] & 0x7fffffff
- def get_provisioning_uri(self, account_name, counter, issuer=None):
- return generate_uri(self, 'hotp', account_name, issuer, [
+ def get_provisioning_uri(self, account_name, counter, issuer):
+ return _generate_uri(self, 'hotp', account_name, issuer, [
('counter', int(counter)),
])
diff --git a/src/cryptography/hazmat/primitives/twofactor/totp.py b/src/cryptography/hazmat/primitives/twofactor/totp.py
index 9c8eddad..98493b6d 100644
--- a/src/cryptography/hazmat/primitives/twofactor/totp.py
+++ b/src/cryptography/hazmat/primitives/twofactor/totp.py
@@ -11,7 +11,7 @@ from cryptography.hazmat.backends.interfaces import HMACBackend
from cryptography.hazmat.primitives import constant_time
from cryptography.hazmat.primitives.twofactor import InvalidToken
from cryptography.hazmat.primitives.twofactor.hotp import HOTP
-from cryptography.hazmat.primitives.twofactor.utils import generate_uri
+from cryptography.hazmat.primitives.twofactor.utils import _generate_uri
class TOTP(object):
@@ -33,7 +33,7 @@ class TOTP(object):
if not constant_time.bytes_eq(self.generate(time), totp):
raise InvalidToken("Supplied TOTP value does not match.")
- def get_provisioning_uri(self, account_name, issuer=None):
- return generate_uri(self._hotp, 'totp', account_name, issuer, [
+ def get_provisioning_uri(self, account_name, issuer):
+ return _generate_uri(self._hotp, 'totp', account_name, issuer, [
('period', int(self._time_step)),
])
diff --git a/src/cryptography/hazmat/primitives/twofactor/utils.py b/src/cryptography/hazmat/primitives/twofactor/utils.py
index 89d38ff2..ae32058b 100644
--- a/src/cryptography/hazmat/primitives/twofactor/utils.py
+++ b/src/cryptography/hazmat/primitives/twofactor/utils.py
@@ -1,11 +1,11 @@
-from __future__ import unicode_literals
+from __future__ import absolute_import, division, print_function
import base64
from six.moves.urllib.parse import quote, urlencode
-def generate_uri(hotp, type_name, account_name, issuer, extra_parameters):
+def _generate_uri(hotp, type_name, account_name, issuer, extra_parameters):
parameters = [
('digits', hotp._length),
('secret', base64.b32encode(hotp._key)),
diff --git a/tests/hazmat/primitives/twofactor/test_hotp.py b/tests/hazmat/primitives/twofactor/test_hotp.py
index 3359dac2..ab5f93c5 100644
--- a/tests/hazmat/primitives/twofactor/test_hotp.py
+++ b/tests/hazmat/primitives/twofactor/test_hotp.py
@@ -96,11 +96,11 @@ class TestHOTP(object):
secret = b"12345678901234567890"
hotp = HOTP(secret, 6, SHA1(), backend)
- assert hotp.get_provisioning_uri("Alice Smith", 1) == (
+ assert hotp.get_provisioning_uri("Alice Smith", 1, None) == (
"otpauth://hotp/Alice%20Smith?digits=6&secret=GEZDGNBV"
"GY3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&counter=1")
- assert hotp.get_provisioning_uri("Alice Smith", 1, issuer='Foo') == (
+ assert hotp.get_provisioning_uri("Alice Smith", 1, 'Foo') == (
"otpauth://hotp/Foo:Alice%20Smith?digits=6&secret=GEZD"
"GNBVGY3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&issuer=Foo"
"&counter=1")
diff --git a/tests/hazmat/primitives/twofactor/test_totp.py b/tests/hazmat/primitives/twofactor/test_totp.py
index cd841ba6..95829713 100644
--- a/tests/hazmat/primitives/twofactor/test_totp.py
+++ b/tests/hazmat/primitives/twofactor/test_totp.py
@@ -130,7 +130,7 @@ class TestTOTP(object):
secret = b"12345678901234567890"
totp = TOTP(secret, 6, hashes.SHA1(), 30, backend=backend)
- assert totp.get_provisioning_uri("Alice Smith") == (
+ assert totp.get_provisioning_uri("Alice Smith", None) == (
"otpauth://totp/Alice%20Smith?digits=6&secret=GEZDGNBVG"
"Y3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&period=30")