mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
chore: improve error message
This commit is contained in:
parent
52b6fa6fbd
commit
882ab4001d
@ -17,16 +17,15 @@ pub enum RequestIdentityError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create an identity object from a certificate and key
|
/// Create an identity object from a certificate and key
|
||||||
pub(crate) fn create_identity_from_pem(
|
pub fn create_identity_from_pem(cert: &str, key: Option<&str>, passphrase: Option<&str>) -> anyhow::Result<Identity> {
|
||||||
cert: &str,
|
let cert_pem = fs::read(cert).map_err(|err| anyhow::anyhow!("Failed to read certificate file: {}", err))?;
|
||||||
key: Option<&str>,
|
|
||||||
passphrase: Option<&str>,
|
|
||||||
) -> anyhow::Result<Identity> {
|
|
||||||
let cert_pem = fs::read(cert)?;
|
|
||||||
|
|
||||||
// Get the private key pem
|
// Get the private key pem
|
||||||
let key_pem = match key {
|
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 => {
|
None => {
|
||||||
// If key is not provided, find the private key in the cert pem
|
// If key is not provided, find the private key in the cert pem
|
||||||
parse_many(&cert_pem)?
|
parse_many(&cert_pem)?
|
||||||
@ -57,7 +56,7 @@ pub(crate) fn create_identity_from_pem(
|
|||||||
Ok(identity)
|
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 pkcs12 = fs::read(pkcs12)?;
|
||||||
|
|
||||||
let Some(passphrase) = passphrase else {
|
let Some(passphrase) = passphrase else {
|
||||||
|
Loading…
Reference in New Issue
Block a user