Skip to content

Commit fe3f7bd

Browse files
committed
two more test cases handled
1 parent bda9e46 commit fe3f7bd

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/rust/src/pkcs7.rs

Lines changed: 4 additions & 3 deletions
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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,22 @@ def test_pkcs7_verify_der_no_content(
11741174
with pytest.raises(ValueError):
11751175
pkcs7.pkcs7_verify_der(signature)
11761176

1177+
def test_pkcs7_verify_der_ecdsa_certificate(self, backend, data):
1178+
# Getting an ECDSA certificate
1179+
certificate, private_key = _load_cert_key()
1180+
1181+
# Signature
1182+
builder = (
1183+
pkcs7.PKCS7SignatureBuilder()
1184+
.set_data(data)
1185+
.add_signer(certificate, private_key, hashes.SHA256())
1186+
)
1187+
signature = builder.sign(serialization.Encoding.DER, [])
1188+
1189+
# Verification with another certificate
1190+
options = [pkcs7.PKCS7Options.NoVerify]
1191+
pkcs7.pkcs7_verify_der(signature, options=options)
1192+
11771193
def test_pkcs7_verify_invalid_signature(
11781194
self, backend, data, certificate, private_key
11791195
):
@@ -1209,6 +1225,21 @@ def test_pkcs7_verify_der_wrong_certificate(
12091225
with pytest.raises(ValueError):
12101226
pkcs7.pkcs7_verify_der(signature, certificate=rsa_certificate)
12111227

1228+
def test_pkcs7_verify_der_unsupported_digest_algorithm(
1229+
self, backend, data, certificate, private_key
1230+
):
1231+
# Signature
1232+
builder = (
1233+
pkcs7.PKCS7SignatureBuilder()
1234+
.set_data(data)
1235+
.add_signer(certificate, private_key, hashes.SHA384())
1236+
)
1237+
signature = builder.sign(serialization.Encoding.DER, [])
1238+
1239+
# Verification with another certificate
1240+
with pytest.raises(exceptions.UnsupportedAlgorithm):
1241+
pkcs7.pkcs7_verify_der(signature)
1242+
12121243
def test_pkcs7_verify_pem(self, backend, data, certificate, private_key):
12131244
# Signature
12141245
builder = (

0 commit comments

Comments
 (0)