aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.rst2
-rw-r--r--docs/hazmat/primitives/asymmetric/rsa.rst8
-rw-r--r--docs/hazmat/primitives/asymmetric/serialization.rst11
-rw-r--r--src/cryptography/hazmat/backends/openssl/rsa.py2
-rw-r--r--src/cryptography/hazmat/primitives/asymmetric/rsa.py2
-rw-r--r--tests/hazmat/backends/test_openssl.py4
-rw-r--r--tests/hazmat/primitives/test_rsa.py28
7 files changed, 30 insertions, 27 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 8f40d287..f0e373be 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -83,7 +83,7 @@ Changelog
and deprecated
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithNumbers`.
* Added
- :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.as_bytes`
+ :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`
to
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization`.
diff --git a/docs/hazmat/primitives/asymmetric/rsa.rst b/docs/hazmat/primitives/asymmetric/rsa.rst
index adb5cbfc..924696db 100644
--- a/docs/hazmat/primitives/asymmetric/rsa.rst
+++ b/docs/hazmat/primitives/asymmetric/rsa.rst
@@ -86,13 +86,13 @@ Key serialization
If you have a key that you've loaded or generated which implements the
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization`
interface you can use
-:meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.as_bytes`
+:meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`
to serialize the key.
.. doctest::
>>> from cryptography.hazmat.primitives import serialization
- >>> pem = private_key.as_bytes(
+ >>> pem = private_key.private_bytes(
... encoding=serialization.Encoding.PEM,
... format=serialization.Format.PKCS8,
... encryption_algorithm=serialization.BestAvailableEncryption(b'mypassword')
@@ -105,7 +105,7 @@ It is also possible to serialize without encryption using
.. doctest::
- >>> pem = private_key.as_bytes(
+ >>> pem = private_key.private_bytes(
... encoding=serialization.Encoding.PEM,
... format=serialization.Format.TraditionalOpenSSL,
... encryption_algorithm=serialization.NoEncryption()
@@ -534,7 +534,7 @@ Key interfaces
:class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateNumbers`
instance.
- .. method:: as_bytes(encoding, format, encryption_algorithm)
+ .. method:: private_bytes(encoding, format, encryption_algorithm)
Allows serialization of the key to bytes. Encoding (
:attr:`~cryptography.hazmat.primitives.serialization.Encoding.PEM` or
diff --git a/docs/hazmat/primitives/asymmetric/serialization.rst b/docs/hazmat/primitives/asymmetric/serialization.rst
index 36ba241b..4940ebd4 100644
--- a/docs/hazmat/primitives/asymmetric/serialization.rst
+++ b/docs/hazmat/primitives/asymmetric/serialization.rst
@@ -290,7 +290,8 @@ Serialization Formats
.. versionadded:: 0.8
- An enumeration for key formats.
+ An enumeration for key formats. Used with
+ :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`.
.. attribute:: TraditionalOpenSSL
@@ -310,7 +311,8 @@ Serialization Encodings
.. versionadded:: 0.8
- An enumeration for encoding types.
+ An enumeration for encoding types. Used with
+ :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`.
.. attribute:: PEM
@@ -328,9 +330,10 @@ Serialization Encryption Types
Objects with this interface are usable as encryption types with methods
like
- :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.as_bytes`.
+ :meth:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`.
All other classes in this section represent the available choices for
- encryption and have this interface.
+ encryption and have this interface. They are used with
+ :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization.private_bytes`.
.. class:: BestAvailableEncryption(password)
diff --git a/src/cryptography/hazmat/backends/openssl/rsa.py b/src/cryptography/hazmat/backends/openssl/rsa.py
index ce6f646c..e7365c11 100644
--- a/src/cryptography/hazmat/backends/openssl/rsa.py
+++ b/src/cryptography/hazmat/backends/openssl/rsa.py
@@ -565,7 +565,7 @@ class _RSAPrivateKey(object):
)
)
- def as_bytes(self, encoding, format, encryption_algorithm):
+ def private_bytes(self, encoding, format, encryption_algorithm):
if not isinstance(encoding, Encoding):
raise TypeError("encoding must be an item from the Encoding enum")
diff --git a/src/cryptography/hazmat/primitives/asymmetric/rsa.py b/src/cryptography/hazmat/primitives/asymmetric/rsa.py
index 932868e1..4963d85c 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, format, encryption_algorithm):
+ def private_bytes(self, encoding, format, encryption_algorithm):
"""
Returns the key serialized as bytes.
"""
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py
index 8cf14b98..4f44f686 100644
--- a/tests/hazmat/backends/test_openssl.py
+++ b/tests/hazmat/backends/test_openssl.py
@@ -502,7 +502,7 @@ class TestRSAPEMSerialization(object):
password = b"x" * 1024
key = RSA_KEY_2048.private_key(backend)
with pytest.raises(ValueError):
- key.as_bytes(
+ key.private_bytes(
serialization.Encoding.PEM,
serialization.Format.PKCS8,
serialization.BestAvailableEncryption(password)
@@ -511,7 +511,7 @@ class TestRSAPEMSerialization(object):
def test_unsupported_key_encoding(self):
key = RSA_KEY_2048.private_key(backend)
with pytest.raises(ValueError):
- key.as_bytes(
+ key.private_bytes(
serialization.Encoding.DER,
serialization.Format.PKCS8,
serialization.NoEncryption()
diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py
index dde73b06..0cf94afe 100644
--- a/tests/hazmat/primitives/test_rsa.py
+++ b/tests/hazmat/primitives/test_rsa.py
@@ -1764,10 +1764,10 @@ class TestRSAPEMWriter(object):
]
)
)
- def test_as_bytes_encrypted_pem(self, backend, fmt, password):
+ def test_private_bytes_encrypted_pem(self, backend, fmt, password):
key = RSA_KEY_2048.private_key(backend)
_skip_if_no_serialization(key, backend)
- serialized = key.as_bytes(
+ serialized = key.private_bytes(
serialization.Encoding.PEM,
fmt,
serialization.BestAvailableEncryption(password)
@@ -1783,10 +1783,10 @@ class TestRSAPEMWriter(object):
"fmt",
[serialization.Format.TraditionalOpenSSL, serialization.Format.PKCS8],
)
- def test_as_bytes_unencrypted_pem(self, backend, fmt):
+ def test_private_bytes_unencrypted_pem(self, backend, fmt):
key = RSA_KEY_2048.private_key(backend)
_skip_if_no_serialization(key, backend)
- serialized = key.as_bytes(
+ serialized = key.private_bytes(
serialization.Encoding.PEM,
fmt,
serialization.NoEncryption()
@@ -1798,7 +1798,7 @@ class TestRSAPEMWriter(object):
priv_num = key.private_numbers()
assert loaded_priv_num == priv_num
- def test_as_bytes_traditional_openssl_unencrypted_pem(self, backend):
+ def test_private_bytes_traditional_openssl_unencrypted_pem(self, backend):
key_bytes = load_vectors_from_file(
os.path.join(
"asymmetric",
@@ -1808,48 +1808,48 @@ class TestRSAPEMWriter(object):
lambda pemfile: pemfile.read().encode()
)
key = serialization.load_pem_private_key(key_bytes, None, backend)
- serialized = key.as_bytes(
+ serialized = key.private_bytes(
serialization.Encoding.PEM,
serialization.Format.TraditionalOpenSSL,
serialization.NoEncryption()
)
assert serialized == key_bytes
- def test_as_bytes_invalid_encoding(self, backend):
+ def test_private_bytes_invalid_encoding(self, backend):
key = RSA_KEY_2048.private_key(backend)
_skip_if_no_serialization(key, backend)
with pytest.raises(TypeError):
- key.as_bytes(
+ key.private_bytes(
"notencoding",
serialization.Format.PKCS8,
serialization.NoEncryption()
)
- def test_as_bytes_invalid_format(self, backend):
+ def test_private_bytes_invalid_format(self, backend):
key = RSA_KEY_2048.private_key(backend)
_skip_if_no_serialization(key, backend)
with pytest.raises(TypeError):
- key.as_bytes(
+ key.private_bytes(
serialization.Encoding.PEM,
"invalidformat",
serialization.NoEncryption()
)
- def test_as_bytes_invalid_encryption_algorithm(self, backend):
+ def test_private_bytes_invalid_encryption_algorithm(self, backend):
key = RSA_KEY_2048.private_key(backend)
_skip_if_no_serialization(key, backend)
with pytest.raises(TypeError):
- key.as_bytes(
+ key.private_bytes(
serialization.Encoding.PEM,
serialization.Format.TraditionalOpenSSL,
"notanencalg"
)
- def test_as_bytes_unsupported_encryption_type(self, backend):
+ def test_private_bytes_unsupported_encryption_type(self, backend):
key = RSA_KEY_2048.private_key(backend)
_skip_if_no_serialization(key, backend)
with pytest.raises(ValueError):
- key.as_bytes(
+ key.private_bytes(
serialization.Encoding.PEM,
serialization.Format.TraditionalOpenSSL,
DummyKeyEncryption()