use crate::TlsError;
use rustls::RootCertStore as RustlsRootCertStore;
use rustls_pki_types::PrivatePkcs8KeyDer;
use rustls_pki_types::{CertificateDer, PrivateKeyDer};
#[cfg(feature = "std")]
use std::{fs::File, io::Read, path::Path};
#[cfg(feature = "std")]
pub fn load_cert_der_file(ca_path: &Path) -> Result<CertificateDer<'static>, TlsError> {
let mut pkcs10_file = File::open(ca_path).unwrap();
let mut pkcs10_data: Vec<u8> = vec![];
pkcs10_file.read_to_end(&mut pkcs10_data).unwrap();
Ok(CertificateDer::from_pem_slice(&pkcs10_data).unwrap())
}
use rustls_pki_types::pem::PemObject;
#[cfg(feature = "std")]
pub fn load_private_key_der_file(key_path: &Path) -> Result<PrivateKeyDer<'static>, TlsError> {
let pk = PrivateKeyDer::from_pem_file(key_path).unwrap();
Ok(pk)
}
pub fn roots(ca_pinned: CertificateDer<'_>) -> RustlsRootCertStore {
let mut roots = RustlsRootCertStore::empty();
roots.add(ca_pinned).unwrap();
roots
}