diff options
Diffstat (limited to 'src/cryptography/hazmat/primitives/twofactor/utils.py')
-rw-r--r-- | src/cryptography/hazmat/primitives/twofactor/utils.py | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/src/cryptography/hazmat/primitives/twofactor/utils.py b/src/cryptography/hazmat/primitives/twofactor/utils.py index 43f50b30..89d38ff2 100644 --- a/src/cryptography/hazmat/primitives/twofactor/utils.py +++ b/src/cryptography/hazmat/primitives/twofactor/utils.py @@ -5,25 +5,7 @@ import base64 from six.moves.urllib.parse import quote, urlencode -__all__ = ['get_provisioning_uri'] - - -def get_provisioning_uri(otp, account_name, issuer=None, counter=None): - """Generates a provisioning URI which can be recognized by Two-Factor - Authentication Apps. See also: http://git.io/vkvvY - - :param otp: An instance of - :class:`cryptography.hazmat.primitives.twofactor.hotp.HOTP` or - :class:`cryptography.hazmat.primitives.twofactor.totp.TOTP`. - :param account_name: The display name of account, such as - ``'Alice Smith'`` or ``'alice@example.com'``. - :param issuer: The display name of issuer. - :param counter: The current value of counter. It is required for HOTP. - :return: The URI string. - :raises RuntimeError: if counter is missing but otp type is HOTP - """ - hotp = getattr(otp, '_hotp', otp) - +def generate_uri(hotp, type_name, account_name, issuer, extra_parameters): parameters = [ ('digits', hotp._length), ('secret', base64.b32encode(hotp._key)), @@ -33,16 +15,10 @@ def get_provisioning_uri(otp, account_name, issuer=None, counter=None): if issuer is not None: parameters.append(('issuer', issuer)) - if hotp is otp: - if counter is None: - raise RuntimeError('"counter" is required for HOTP') - parameters.append(('counter', int(counter))) - - if hasattr(otp, '_time_step'): - parameters.append(('period', int(otp._time_step))) + parameters.extend(extra_parameters) uriparts = { - 'type': otp.__class__.__name__.lower(), + 'type': type_name, 'label': ('%s:%s' % (quote(issuer), quote(account_name)) if issuer else quote(account_name)), 'parameters': urlencode(parameters), |