mirror of
https://git.proxmox.com/git/proxmox
synced 2025-10-04 19:39:30 +00:00
client: add TlsOptions::parse_fingerprint
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
dff830ba04
commit
604e467684
@ -11,6 +11,7 @@ repository.workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
base64.workspace = true
|
base64.workspace = true
|
||||||
|
hex.workspace = true
|
||||||
http.workspace = true
|
http.workspace = true
|
||||||
once_cell.workspace = true
|
once_cell.workspace = true
|
||||||
percent-encoding.workspace = true
|
percent-encoding.workspace = true
|
||||||
|
@ -17,6 +17,7 @@ use proxmox_login::ticket::Validity;
|
|||||||
use proxmox_login::{Login, SecondFactorChallenge, TicketResult};
|
use proxmox_login::{Login, SecondFactorChallenge, TicketResult};
|
||||||
|
|
||||||
use crate::auth::AuthenticationKind;
|
use crate::auth::AuthenticationKind;
|
||||||
|
use crate::error::ParseFingerprintError;
|
||||||
use crate::{Error, Token};
|
use crate::{Error, Token};
|
||||||
|
|
||||||
use super::{HttpApiClient, HttpApiResponse};
|
use super::{HttpApiClient, HttpApiResponse};
|
||||||
@ -40,6 +41,23 @@ pub enum TlsOptions {
|
|||||||
Callback(Box<dyn Fn(bool, &mut x509::X509StoreContextRef) -> bool + Send + Sync + 'static>),
|
Callback(Box<dyn Fn(bool, &mut x509::X509StoreContextRef) -> bool + Send + Sync + 'static>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TlsOptions {
|
||||||
|
pub fn parse_fingerprint(fp: &str) -> Result<Self, ParseFingerprintError> {
|
||||||
|
use hex::FromHex;
|
||||||
|
|
||||||
|
let hex: Vec<u8> = fp
|
||||||
|
.as_bytes()
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.filter(|&b| b != b':')
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let fp = <[u8; 32]>::from_hex(&hex).map_err(|_| ParseFingerprintError)?;
|
||||||
|
|
||||||
|
Ok(Self::Fingerprint(fp.into()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A Proxmox API client base backed by a [`proxmox_http::Client`].
|
/// A Proxmox API client base backed by a [`proxmox_http::Client`].
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
api_url: Uri,
|
api_url: Uri,
|
||||||
|
@ -85,3 +85,14 @@ impl Error {
|
|||||||
Self::Api(status, msg.into())
|
Self::Api(status, msg.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub struct ParseFingerprintError;
|
||||||
|
|
||||||
|
impl StdError for ParseFingerprintError {}
|
||||||
|
|
||||||
|
impl fmt::Display for ParseFingerprintError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
f.write_str("failed to parse fingerprint")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user