aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2019-01-17 09:43:47 -0600
committerAlex Gaynor <alex.gaynor@gmail.com>2019-01-17 10:43:47 -0500
commit5b4c81e39622fc13895bf5df7d0f4f6bd067e7a0 (patch)
tree70ae40472a57cad2b25d9fba7044f3a719e7c05f /tests/hazmat
parent8d9ea52be9e7de1373641d3afaed9b292cb03f43 (diff)
downloadcryptography-5b4c81e39622fc13895bf5df7d0f4f6bd067e7a0.tar.gz
cryptography-5b4c81e39622fc13895bf5df7d0f4f6bd067e7a0.tar.bz2
cryptography-5b4c81e39622fc13895bf5df7d0f4f6bd067e7a0.zip
x448 and x25519 should enforce key lengths in backend (#4703)
* x448 and x25519 should enforce key lengths in from_private_bytes they should also check if the algorithm is supported like the public bytes class methods do * oops * move the checks
Diffstat (limited to 'tests/hazmat')
-rw-r--r--tests/hazmat/primitives/test_x25519.py10
-rw-r--r--tests/hazmat/primitives/test_x448.py12
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/hazmat/primitives/test_x25519.py b/tests/hazmat/primitives/test_x25519.py
index 682c3125..f412f2e8 100644
--- a/tests/hazmat/primitives/test_x25519.py
+++ b/tests/hazmat/primitives/test_x25519.py
@@ -32,6 +32,9 @@ def test_x25519_unsupported(backend):
X25519PublicKey.from_public_bytes(b"0" * 32)
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM):
+ X25519PrivateKey.from_private_bytes(b"0" * 32)
+
+ with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM):
X25519PrivateKey.generate()
@@ -166,6 +169,13 @@ class TestX25519Exchange(object):
with pytest.raises(ValueError):
X25519PublicKey.from_public_bytes(b"a" * 33)
+ def test_invalid_length_from_private_bytes(self, backend):
+ with pytest.raises(ValueError):
+ X25519PrivateKey.from_private_bytes(b"a" * 31)
+
+ with pytest.raises(ValueError):
+ X25519PrivateKey.from_private_bytes(b"a" * 33)
+
def test_invalid_private_bytes(self, backend):
key = X25519PrivateKey.generate()
with pytest.raises(ValueError):
diff --git a/tests/hazmat/primitives/test_x448.py b/tests/hazmat/primitives/test_x448.py
index 51be0e10..817de76f 100644
--- a/tests/hazmat/primitives/test_x448.py
+++ b/tests/hazmat/primitives/test_x448.py
@@ -28,7 +28,10 @@ from ...utils import (
@pytest.mark.requires_backend_interface(interface=DHBackend)
def test_x448_unsupported(backend):
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM):
- X448PublicKey.from_public_bytes(b"0" * 32)
+ X448PublicKey.from_public_bytes(b"0" * 56)
+
+ with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM):
+ X448PrivateKey.from_private_bytes(b"0" * 56)
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_EXCHANGE_ALGORITHM):
X448PrivateKey.generate()
@@ -176,6 +179,13 @@ class TestX448Exchange(object):
with pytest.raises(ValueError):
X448PublicKey.from_public_bytes(b"a" * 57)
+ def test_invalid_length_from_private_bytes(self, backend):
+ with pytest.raises(ValueError):
+ X448PrivateKey.from_private_bytes(b"a" * 55)
+
+ with pytest.raises(ValueError):
+ X448PrivateKey.from_private_bytes(b"a" * 57)
+
def test_invalid_private_bytes(self, backend):
key = X448PrivateKey.generate()
with pytest.raises(ValueError):