diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2018-11-23 22:17:44 +0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2018-11-23 08:17:44 -0600 |
commit | bf621bafc55f225f9532ea29a0a88702a93c232e (patch) | |
tree | 73b2295f8e951be20a8ce515a45044f56e598920 /src | |
parent | 8ec59bef65914d340b19106068a2063a60b12139 (diff) | |
download | cryptography-bf621bafc55f225f9532ea29a0a88702a93c232e.tar.gz cryptography-bf621bafc55f225f9532ea29a0a88702a93c232e.tar.bz2 cryptography-bf621bafc55f225f9532ea29a0a88702a93c232e.zip |
refactor serialization module into package (#4606)
* refactor serialization into a package so we can add a pkcs12 module
* oops
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/backend.py | 25 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/serialization/__init__.py | 21 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/serialization/base.py (renamed from src/cryptography/hazmat/primitives/serialization.py) | 0 |
3 files changed, 35 insertions, 11 deletions
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py index c8a46b98..5d73a7e8 100644 --- a/src/cryptography/hazmat/backends/openssl/backend.py +++ b/src/cryptography/hazmat/backends/openssl/backend.py @@ -75,6 +75,9 @@ from cryptography.hazmat.primitives.ciphers.modes import ( CBC, CFB, CFB8, CTR, ECB, GCM, OFB, XTS ) from cryptography.hazmat.primitives.kdf import scrypt +from cryptography.hazmat.primitives.serialization.base import ( + _ssh_write_mpint, _ssh_write_string +) from cryptography.x509 import ocsp @@ -1795,19 +1798,19 @@ class Backend(object): if isinstance(key, rsa.RSAPublicKey): public_numbers = key.public_numbers() return b"ssh-rsa " + base64.b64encode( - serialization._ssh_write_string(b"ssh-rsa") + - serialization._ssh_write_mpint(public_numbers.e) + - serialization._ssh_write_mpint(public_numbers.n) + _ssh_write_string(b"ssh-rsa") + + _ssh_write_mpint(public_numbers.e) + + _ssh_write_mpint(public_numbers.n) ) elif isinstance(key, dsa.DSAPublicKey): public_numbers = key.public_numbers() parameter_numbers = public_numbers.parameter_numbers return b"ssh-dss " + base64.b64encode( - serialization._ssh_write_string(b"ssh-dss") + - serialization._ssh_write_mpint(parameter_numbers.p) + - serialization._ssh_write_mpint(parameter_numbers.q) + - serialization._ssh_write_mpint(parameter_numbers.g) + - serialization._ssh_write_mpint(public_numbers.y) + _ssh_write_string(b"ssh-dss") + + _ssh_write_mpint(parameter_numbers.p) + + _ssh_write_mpint(parameter_numbers.q) + + _ssh_write_mpint(parameter_numbers.g) + + _ssh_write_mpint(public_numbers.y) ) else: assert isinstance(key, ec.EllipticCurvePublicKey) @@ -1824,9 +1827,9 @@ class Backend(object): "supported by the SSH public key format" ) return b"ecdsa-sha2-" + curve_name + b" " + base64.b64encode( - serialization._ssh_write_string(b"ecdsa-sha2-" + curve_name) + - serialization._ssh_write_string(curve_name) + - serialization._ssh_write_string(public_numbers.encode_point()) + _ssh_write_string(b"ecdsa-sha2-" + curve_name) + + _ssh_write_string(curve_name) + + _ssh_write_string(public_numbers.encode_point()) ) def _parameter_bytes(self, encoding, format, cdata): diff --git a/src/cryptography/hazmat/primitives/serialization/__init__.py b/src/cryptography/hazmat/primitives/serialization/__init__.py new file mode 100644 index 00000000..cff775b8 --- /dev/null +++ b/src/cryptography/hazmat/primitives/serialization/__init__.py @@ -0,0 +1,21 @@ +# This file is dual licensed under the terms of the Apache License, Version +# 2.0, and the BSD License. See the LICENSE file in the root of this repository +# for complete details. + +from __future__ import absolute_import, division, print_function + +from cryptography.hazmat.primitives.serialization.base import ( + BestAvailableEncryption, Encoding, KeySerializationEncryption, + NoEncryption, ParameterFormat, PrivateFormat, PublicFormat, + load_der_parameters, load_der_private_key, load_der_public_key, + load_pem_parameters, load_pem_private_key, load_pem_public_key, + load_ssh_public_key, +) + +__all__ = [ + "load_der_parameters", "load_der_private_key", "load_der_public_key", + "load_pem_parameters", "load_pem_private_key", "load_pem_public_key", + "load_ssh_public_key", "Encoding", "PrivateFormat", "PublicFormat", + "ParameterFormat", "KeySerializationEncryption", "BestAvailableEncryption", + "NoEncryption", +] diff --git a/src/cryptography/hazmat/primitives/serialization.py b/src/cryptography/hazmat/primitives/serialization/base.py index bd09e6e3..bd09e6e3 100644 --- a/src/cryptography/hazmat/primitives/serialization.py +++ b/src/cryptography/hazmat/primitives/serialization/base.py |