aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2019-01-15 21:52:08 -0600
committerAlex Gaynor <alex.gaynor@gmail.com>2019-01-15 22:52:08 -0500
commit9c2f3d6a05b117247b37323e1f8ed1cf6fa263d1 (patch)
tree13969efb771c6b57556ea8f8206ecd7a54bdaa21
parent2f34994fe909d8862225c03427c7b4525fff4190 (diff)
downloadplatform_external_python_cryptography-9c2f3d6a05b117247b37323e1f8ed1cf6fa263d1.tar.gz
platform_external_python_cryptography-9c2f3d6a05b117247b37323e1f8ed1cf6fa263d1.tar.bz2
platform_external_python_cryptography-9c2f3d6a05b117247b37323e1f8ed1cf6fa263d1.zip
support byteslike in X448PrivateKey.from_private_bytes (#4694)
-rw-r--r--docs/hazmat/primitives/asymmetric/x448.rst3
-rw-r--r--src/cryptography/hazmat/backends/openssl/backend.py3
-rw-r--r--tests/hazmat/primitives/test_x448.py12
3 files changed, 16 insertions, 2 deletions
diff --git a/docs/hazmat/primitives/asymmetric/x448.rst b/docs/hazmat/primitives/asymmetric/x448.rst
index 9b00c6af..4e1f0421 100644
--- a/docs/hazmat/primitives/asymmetric/x448.rst
+++ b/docs/hazmat/primitives/asymmetric/x448.rst
@@ -68,7 +68,8 @@ Key interfaces
.. classmethod:: from_private_bytes(data)
- :param bytes data: 56 byte private key.
+ :param data: 56 byte private key.
+ :type data: :term:`bytes-like`
:returns: :class:`X448PrivateKey`
diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
index 89356d3c..3ab34c17 100644
--- a/src/cryptography/hazmat/backends/openssl/backend.py
+++ b/src/cryptography/hazmat/backends/openssl/backend.py
@@ -2150,8 +2150,9 @@ class Backend(object):
return _X448PublicKey(self, evp_pkey)
def x448_load_private_bytes(self, data):
+ data_ptr = self._ffi.from_buffer(data)
evp_pkey = self._lib.EVP_PKEY_new_raw_private_key(
- self._lib.NID_X448, self._ffi.NULL, data, len(data)
+ self._lib.NID_X448, self._ffi.NULL, data_ptr, len(data)
)
self.openssl_assert(evp_pkey != self._ffi.NULL)
evp_pkey = self._ffi.gc(evp_pkey, self._lib.EVP_PKEY_free)
diff --git a/tests/hazmat/primitives/test_x448.py b/tests/hazmat/primitives/test_x448.py
index 1833b03d..51be0e10 100644
--- a/tests/hazmat/primitives/test_x448.py
+++ b/tests/hazmat/primitives/test_x448.py
@@ -218,3 +218,15 @@ class TestX448Exchange(object):
serialization.Encoding.PEM,
serialization.PublicFormat.Raw
)
+
+ def test_buffer_protocol(self, backend):
+ private_bytes = binascii.unhexlify(
+ b"9a8f4925d1519f5775cf46b04b5800d4ee9ee8bae8bc5565d498c28d"
+ b"d9c9baf574a9419744897391006382a6f127ab1d9ac2d8c0a598726b"
+ )
+ key = X448PrivateKey.from_private_bytes(bytearray(private_bytes))
+ assert key.private_bytes(
+ serialization.Encoding.Raw,
+ serialization.PrivateFormat.Raw,
+ serialization.NoEncryption()
+ ) == private_bytes