aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-17 08:42:42 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-17 08:42:42 -0600
commit2cfa45fd168273eaf3b616730255fc063faf5257 (patch)
tree38f5fedbf4e5385bf4ed0147109fd79c794c27a7 /src
parent75257daa6d21a1e79565176f7ee90c3ebb4a4680 (diff)
downloadcryptography-2cfa45fd168273eaf3b616730255fc063faf5257.tar.gz
cryptography-2cfa45fd168273eaf3b616730255fc063faf5257.tar.bz2
cryptography-2cfa45fd168273eaf3b616730255fc063faf5257.zip
update docs, hoist b64decode up and re-add test for it
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/primitives/serialization.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/cryptography/hazmat/primitives/serialization.py b/src/cryptography/hazmat/primitives/serialization.py
index 1949b111..61a69a5d 100644
--- a/src/cryptography/hazmat/primitives/serialization.py
+++ b/src/cryptography/hazmat/primitives/serialization.py
@@ -58,20 +58,23 @@ def load_ssh_public_key(data, backend):
key_type = key_parts[0]
key_body = key_parts[1]
+ try:
+ decoded_data = base64.b64decode(key_body)
+ except TypeError:
+ raise ValueError('Key is not in the proper format.')
+
if key_type.startswith(b'ssh-rsa'):
- return _load_ssh_rsa_public_key(key_body, backend)
+ return _load_ssh_rsa_public_key(decoded_data, backend)
elif key_type.startswith(b'ssh-dss'):
- return _load_ssh_dss_public_key(key_body, backend)
+ return _load_ssh_dss_public_key(decoded_data, backend)
else:
raise UnsupportedAlgorithm(
'Only RSA and DSA keys are currently supported.'
)
-def _load_ssh_rsa_public_key(key_body, backend):
- data = base64.b64decode(key_body)
-
- key_type, rest = _read_next_string(data)
+def _load_ssh_rsa_public_key(decoded_data, backend):
+ key_type, rest = _read_next_string(decoded_data)
e, rest = _read_next_mpint(rest)
n, rest = _read_next_mpint(rest)
@@ -85,10 +88,8 @@ def _load_ssh_rsa_public_key(key_body, backend):
return backend.load_rsa_public_numbers(RSAPublicNumbers(e, n))
-def _load_ssh_dss_public_key(key_body, backend):
- data = base64.b64decode(key_body)
-
- key_type, rest = _read_next_string(data)
+def _load_ssh_dss_public_key(decoded_data, backend):
+ key_type, rest = _read_next_string(decoded_data)
p, rest = _read_next_mpint(rest)
q, rest = _read_next_mpint(rest)
g, rest = _read_next_mpint(rest)