Skip to content

Commit b580fcf

Browse files
alexclaude
andauthored
Include exact error details in PKCS#12 DER parsing warning (#13722)
Updates the PKCS#12 warning message to include the specific error details when DER parsing fails, matching the recent improvement made to PKCS#7 warnings. This provides users with more actionable information about why their PKCS#12 bundle couldn't be parsed as DER. The warning now captures and displays the actual parsing error instead of just indicating that parsing failed. Co-authored-by: Claude <noreply@anthropic.com>
1 parent f6c3118 commit b580fcf

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/rust/src/pkcs12.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,10 @@ fn decode_p12(
567567
.parse2(password)
568568
.map_err(|_| pyo3::exceptions::PyValueError::new_err("Invalid password or PKCS12 data"))?;
569569

570-
if asn1::parse_single::<cryptography_x509::pkcs12::Pfx<'_>>(data.as_bytes()).is_err() {
570+
if let Err(e) = asn1::parse_single::<cryptography_x509::pkcs12::Pfx<'_>>(data.as_bytes()) {
571571
let warning_cls = pyo3::exceptions::PyUserWarning::type_object(py);
572-
let message = c"PKCS#12 bundle 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#12 bundle was created. In the future, this may become an exception.";
573-
pyo3::PyErr::warn(py, &warning_cls, message, 1)?;
572+
let message = std::ffi::CString::new(format!("PKCS#12 bundle 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#12 bundle was created. In the future, this may become an exception. Error details: {e}")).unwrap();
573+
pyo3::PyErr::warn(py, &warning_cls, &message, 1)?;
574574
}
575575

576576
Ok(parsed)

0 commit comments

Comments
 (0)