fixes #11175 -- improve error message when loading PEM public key with no BEGIN PUBLIC KEY (#11177)

This commit is contained in:
Alex Gaynor 2024-06-30 07:06:05 -04:00 committed by GitHub
parent 6d2d8c2e37
commit 95e57bf5c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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())
}