Skip to content

Commit

Permalink
chore: improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
yuezk committed May 19, 2024
1 parent 52b6fa6 commit 882ab40
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/gpapi/src/utils/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ pub enum RequestIdentityError {
}

/// Create an identity object from a certificate and key
pub(crate) fn create_identity_from_pem(
cert: &str,
key: Option<&str>,
passphrase: Option<&str>,
) -> anyhow::Result<Identity> {
let cert_pem = fs::read(cert)?;
pub fn create_identity_from_pem(cert: &str, key: Option<&str>, passphrase: Option<&str>) -> anyhow::Result<Identity> {
let cert_pem = fs::read(cert).map_err(|err| anyhow::anyhow!("Failed to read certificate file: {}", err))?;

// Get the private key pem
let key_pem = match key {
Some(key) => pem::parse(fs::read(key)?)?,
Some(key) => {
let pem_file = fs::read(key).map_err(|err| anyhow::anyhow!("Failed to read key file: {}", err))?;
pem::parse(pem_file)?
}
None => {
// If key is not provided, find the private key in the cert pem
parse_many(&cert_pem)?
Expand Down Expand Up @@ -57,7 +56,7 @@ pub(crate) fn create_identity_from_pem(
Ok(identity)
}

pub(crate) fn create_identity_from_pkcs12(pkcs12: &str, passphrase: Option<&str>) -> anyhow::Result<Identity> {
pub fn create_identity_from_pkcs12(pkcs12: &str, passphrase: Option<&str>) -> anyhow::Result<Identity> {
let pkcs12 = fs::read(pkcs12)?;

let Some(passphrase) = passphrase else {
Expand Down

0 comments on commit 882ab40

Please sign in to comment.