Skip to content

Commit dcd3f28

Browse files
committed
two more test cases handled
1 parent 4890d84 commit dcd3f28

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/rust/src/pkcs7.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,10 @@ fn verify_der<'p>(
848848
},
849849
_ => {
850850
return Err(CryptographyError::from(
851-
pyo3::exceptions::PyValueError::new_err(
852-
"Unsupported hash algorithm with RSA.",
853-
),
851+
exceptions::UnsupportedAlgorithm::new_err((
852+
"Only SHA-256 is currently supported for content verification with RSA.",
853+
exceptions::Reasons::UNSUPPORTED_SERIALIZATION,
854+
)),
854855
))
855856
}
856857
},

tests/hazmat/primitives/test_pkcs7.py

+31
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,22 @@ def test_pkcs7_verify_der_no_content(
10311031
with pytest.raises(ValueError):
10321032
pkcs7.pkcs7_verify_der(signature)
10331033

1034+
def test_pkcs7_verify_der_ecdsa_certificate(self, backend, data):
1035+
# Getting an ECDSA certificate
1036+
certificate, private_key = _load_cert_key()
1037+
1038+
# Signature
1039+
builder = (
1040+
pkcs7.PKCS7SignatureBuilder()
1041+
.set_data(data)
1042+
.add_signer(certificate, private_key, hashes.SHA256())
1043+
)
1044+
signature = builder.sign(serialization.Encoding.DER, [])
1045+
1046+
# Verification with another certificate
1047+
options = [pkcs7.PKCS7Options.NoVerify]
1048+
pkcs7.pkcs7_verify_der(signature, options=options)
1049+
10341050
def test_pkcs7_verify_invalid_signature(
10351051
self, backend, data, certificate, private_key
10361052
):
@@ -1066,6 +1082,21 @@ def test_pkcs7_verify_der_wrong_certificate(
10661082
with pytest.raises(ValueError):
10671083
pkcs7.pkcs7_verify_der(signature, certificate=rsa_certificate)
10681084

1085+
def test_pkcs7_verify_der_unsupported_digest_algorithm(
1086+
self, backend, data, certificate, private_key
1087+
):
1088+
# Signature
1089+
builder = (
1090+
pkcs7.PKCS7SignatureBuilder()
1091+
.set_data(data)
1092+
.add_signer(certificate, private_key, hashes.SHA384())
1093+
)
1094+
signature = builder.sign(serialization.Encoding.DER, [])
1095+
1096+
# Verification with another certificate
1097+
with pytest.raises(exceptions.UnsupportedAlgorithm):
1098+
pkcs7.pkcs7_verify_der(signature)
1099+
10691100
def test_pkcs7_verify_pem(self, backend, data, certificate, private_key):
10701101
# Signature
10711102
builder = (

0 commit comments

Comments
 (0)