1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::{fs, io, path::Path, result};
use reqwest::Identity;
use thiserror::Error;
#[derive(Debug)]
pub struct Pkcs12Certificate(Identity);
#[derive(Error, Debug)]
pub enum Pkcs12CertificateError {
#[error(transparent)]
Io(#[from] io::Error),
#[error(transparent)]
Pkcs12(#[from] reqwest::Error),
}
pub type Pkcs12CertificateResult = result::Result<Pkcs12Certificate, Pkcs12CertificateError>;
impl Pkcs12Certificate {
#[inline]
fn from(bytes: &[u8], password: &str) -> Pkcs12CertificateResult {
Ok(Self {
0: Identity::from_pkcs12_der(&bytes, password)?,
})
}
pub fn from_bytes(bytes: &[u8], password: &str) -> Pkcs12CertificateResult {
Self::from(bytes, password)
}
pub fn from_str(string: &str, password: &str) -> Pkcs12CertificateResult {
Self::from(string.as_bytes(), password)
}
pub fn from_file<P: AsRef<Path>>(path: P, password: &str) -> Pkcs12CertificateResult {
let bytes = fs::read(path)?;
Self::from(&bytes, password)
}
pub(crate) fn into_inner(self) -> Identity {
self.0
}
}