From 95e57bf5c5763cf9f700ef339cad3aa7bb5799a4 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 30 Jun 2024 07:06:05 -0400 Subject: [PATCH] fixes #11175 -- improve error message when loading PEM public key with no BEGIN PUBLIC KEY (#11177) --- src/rust/src/backend/keys.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rust/src/backend/keys.rs b/src/rust/src/backend/keys.rs index 7240f98c1..649bea38c 100644 --- a/src/rust/src/backend/keys.rs +++ b/src/rust/src/backend/keys.rs @@ -176,7 +176,9 @@ fn load_pem_public_key( } } "PUBLIC KEY" => cryptography_key_parsing::spki::parse_public_key(p.contents())?, - _ => return Err(CryptographyError::from(pem::PemError::MalformedFraming)), + _ => return Err(CryptographyError::from(pyo3::exceptions::PyValueError::new_err( + "Valid PEM but no BEGIN PUBLIC KEY/END PUBLIC KEY delimiters. Are you sure this is a public key?" + ))), }; public_key_from_pkey(py, &pkey, pkey.id()) }