From 621635712962267e589b19fb2292a764e5ad71de Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Tue, 1 Apr 2014 12:02:02 +0100 Subject: Add _Reasons.UNSUPPORTED_MGF --- cryptography/exceptions.py | 1 + cryptography/hazmat/backends/openssl/backend.py | 6 ++++-- tests/hazmat/primitives/test_rsa.py | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cryptography/exceptions.py b/cryptography/exceptions.py index 4b4d4c37..d2782be6 100644 --- a/cryptography/exceptions.py +++ b/cryptography/exceptions.py @@ -19,6 +19,7 @@ class _Reasons(object): UNSUPPORTED_HASH = object() UNSUPPORTED_CIPHER = object() UNSUPPORTED_PADDING = object() + UNSUPPORTED_MGF = object() class UnsupportedAlgorithm(Exception): diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index 753717d4..3293741c 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -731,7 +731,8 @@ class _RSASignatureContext(object): elif isinstance(padding, PSS): if not isinstance(padding._mgf, MGF1): raise UnsupportedAlgorithm( - "Only MGF1 is supported by this backend" + "Only MGF1 is supported by this backend", + _Reasons.UNSUPPORTED_MGF ) # Size of key in bytes - 2 is the maximum @@ -915,7 +916,8 @@ class _RSAVerificationContext(object): elif isinstance(padding, PSS): if not isinstance(padding._mgf, MGF1): raise UnsupportedAlgorithm( - "Only MGF1 is supported by this backend" + "Only MGF1 is supported by this backend", + _Reasons.UNSUPPORTED_MGF ) # Size of key in bytes - 2 is the maximum diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 5d94e790..32f54945 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -630,7 +630,7 @@ class TestRSASignature(object): key_size=512, backend=backend ) - with pytest.raises(UnsupportedAlgorithm): + with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_MGF): private_key.signer(padding.PSS(mgf=DummyMGF()), hashes.SHA1(), backend) @@ -881,7 +881,7 @@ class TestRSAVerification(object): backend=backend ) public_key = private_key.public_key() - with pytest.raises(UnsupportedAlgorithm): + with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_MGF): public_key.verifier(b"sig", padding.PSS(mgf=DummyMGF()), hashes.SHA1(), backend) -- cgit v1.2.3