Skip to content

Commit 31d0cfd

Browse files
committed
Support NoDigestInfo in recover_data_from_signature
1 parent e08560e commit 31d0cfd

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/cryptography/hazmat/primitives/asymmetric/rsa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def recover_data_from_signature(
123123
self,
124124
signature: bytes,
125125
padding: AsymmetricPadding,
126-
algorithm: hashes.HashAlgorithm | None,
126+
algorithm: hashes.HashAlgorithm | asym_utils.NoDigestInfo | None,
127127
) -> bytes:
128128
"""
129129
Recovers the original data from the signature.

src/rust/src/backend/rsa.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ impl RsaPublicKey {
497497
padding: &pyo3::Bound<'_, pyo3::PyAny>,
498498
algorithm: &pyo3::Bound<'_, pyo3::PyAny>,
499499
) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> {
500+
let algorithm = if algorithm.is_instance(&types::NO_DIGEST_INFO.get(py)?)? {
501+
&pyo3::types::PyNone::get(py).to_owned().into_any()
502+
} else {
503+
algorithm
504+
};
500505
if algorithm.is_instance(&types::PREHASHED.get(py)?)? {
501506
return Err(CryptographyError::from(
502507
pyo3::exceptions::PyTypeError::new_err(

tests/hazmat/primitives/test_rsa.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ def test_pkcs1v15_verification(self, backend, subtests):
955955
# Test recovery of all data (full DigestInfo) with hash alg. as
956956
# None
957957
rec_sig_data = public_key.recover_data_from_signature(
958-
signature, padding.PKCS1v15(), None
958+
signature, padding.PKCS1v15(), asym_utils.NoDigestInfo()
959959
)
960960
assert len(rec_sig_data) > len(msg_digest)
961961
assert msg_digest == rec_sig_data[-len(msg_digest) :]

0 commit comments

Comments
 (0)