Skip to content

Commit f5802fe

Browse files
authored
Include more details on PKCS#7 DER warnings (#13680)
1 parent c17860f commit f5802fe

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/rust/src/pkcs7.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use std::borrow::Cow;
66
use std::collections::HashMap;
7+
#[cfg(not(any(CRYPTOGRAPHY_IS_BORINGSSL, CRYPTOGRAPHY_IS_AWSLC)))]
8+
use std::ffi::CString;
79
use std::mem;
810
use std::ops::Deref;
911
use std::sync::LazyLock;
@@ -836,10 +838,11 @@ fn load_der_pkcs7_certificates(
836838
))
837839
})?;
838840
let result = load_pkcs7_certificates(py, pkcs7_decoded)?;
839-
if load_pkcs7_certificates_rust(py, data).is_err() {
841+
if let Err(e) = load_pkcs7_certificates_rust(py, data) {
842+
let err = pyo3::PyErr::from(e);
840843
let warning_cls = pyo3::exceptions::PyUserWarning::type_object(py);
841-
let message = c"PKCS#7 certificates could not be parsed as DER, falling back to parsing as BER. Please file an issue at https://github.com/pyca/cryptography/issues explaining how your PKCS#7 certificates were created. In the future, this may become an exception.";
842-
pyo3::PyErr::warn(py, &warning_cls, message, 1)?;
844+
let message = CString::new(format!("PKCS#7 certificates could not be parsed as DER, falling back to parsing as BER. Please file an issue at https://github.com/pyca/cryptography/issues explaining how your PKCS#7 certificates were created. In the future, this may become an exception. Error details: {err}")).unwrap();
845+
pyo3::PyErr::warn(py, &warning_cls, &message, 1)?;
843846
}
844847

845848
Ok(result)

0 commit comments

Comments
 (0)