diff options
-rw-r--r-- | docs/hazmat/primitives/asymmetric/rsa.rst | 14 | ||||
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/rsa.py | 10 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/rsa.py | 2 |
3 files changed, 15 insertions, 11 deletions
diff --git a/docs/hazmat/primitives/asymmetric/rsa.rst b/docs/hazmat/primitives/asymmetric/rsa.rst index 80d48497..17e13c28 100644 --- a/docs/hazmat/primitives/asymmetric/rsa.rst +++ b/docs/hazmat/primitives/asymmetric/rsa.rst @@ -94,7 +94,7 @@ to serialize the key. >>> from cryptography.hazmat.primitives import serialization >>> pem = private_key.as_bytes( ... encoding=serialization.Encoding.PEM, - ... fmt=serialization.Format.PKCS8, + ... format=serialization.Format.PKCS8, ... encryption_algorithm=serialization.BestAvailableEncryption(b'mypassword') ... ) >>> pem.splitlines()[0] @@ -107,7 +107,7 @@ It is also possible to serialize without encryption using >>> pem = private_key.as_bytes( ... encoding=serialization.Encoding.PEM, - ... fmt=serialization.Format.TraditionalOpenSSL, + ... format=serialization.Format.TraditionalOpenSSL, ... encryption_algorithm=serialization.NoEncryption() ... ) >>> pem.splitlines()[0] @@ -534,14 +534,18 @@ Key interfaces :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers` instance. - .. method:: as_bytes(encoding, fmt, encryption_algorithm) + .. method:: as_bytes(encoding, format, encryption_algorithm) - Serialize the key to bytes. + Allows serialization of the key to bytes. Encoding (PEM or DER), format + (TraditionalOpenSSL or PKCS8) and encryption algorithm (such as + :class:`~cryptography.hazmat.primitives.serialization.BestAvailableEncryption` + or :class:`~cryptography.hazmat.primitives.serialization.NoEncryption`) + are chosen to define the exact serialization. :param encoding: A value from the :class:`~cryptography.hazmat.primitives.serialization.Encoding` enum. - :param fmt: A value from the + :param format: A value from the :class:`~cryptography.hazmat.primitives.serialization.Format` enum. :param encryption_algorithm: An instance of an object conforming to the diff --git a/src/cryptography/hazmat/backends/openssl/rsa.py b/src/cryptography/hazmat/backends/openssl/rsa.py index 0a1f106f..ce6f646c 100644 --- a/src/cryptography/hazmat/backends/openssl/rsa.py +++ b/src/cryptography/hazmat/backends/openssl/rsa.py @@ -565,21 +565,21 @@ class _RSAPrivateKey(object): ) ) - def as_bytes(self, encoding, fmt, encryption_algorithm): + def as_bytes(self, encoding, format, encryption_algorithm): if not isinstance(encoding, Encoding): raise TypeError("encoding must be an item from the Encoding enum") - if not isinstance(fmt, Format): + if not isinstance(format, Format): raise TypeError("format must be an item from the Format enum") # This is a temporary check until we land DER serialization. - if encoding != Encoding.PEM: + if encoding is not Encoding.PEM: raise ValueError("Only PEM encoding is supported by this backend") - if fmt == Format.PKCS8: + if format is Format.PKCS8: write_bio = self._backend._lib.PEM_write_bio_PKCS8PrivateKey key = self._evp_pkey - elif fmt == Format.TraditionalOpenSSL: + elif format is Format.TraditionalOpenSSL: write_bio = self._backend._lib.PEM_write_bio_RSAPrivateKey key = self._rsa_cdata diff --git a/src/cryptography/hazmat/primitives/asymmetric/rsa.py b/src/cryptography/hazmat/primitives/asymmetric/rsa.py index 160ac6aa..932868e1 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/rsa.py +++ b/src/cryptography/hazmat/primitives/asymmetric/rsa.py @@ -50,7 +50,7 @@ class RSAPrivateKeyWithSerialization(RSAPrivateKey): """ @abc.abstractmethod - def as_bytes(self, encoding, fmt, encryption_algorithm): + def as_bytes(self, encoding, format, encryption_algorithm): """ Returns the key serialized as bytes. """ |