use {
rustls::{crypto::aws_lc_rs::sign::*, sign::*},
rustls_pki_types::*,
std::{io, sync::*},
};
pub fn certified_key_from_pem(certificates_pem: &[u8], private_key_pem: &[u8]) -> io::Result<CertifiedKey> {
let certificates = parse_certificates_pem(certificates_pem)?;
let signing_key = get_signing_key_from_pem(private_key_pem)?;
Ok(CertifiedKey { cert: certificates, key: signing_key, ocsp: None })
}
pub fn parse_certificates_pem(pem: &[u8]) -> io::Result<Vec<CertificateDer<'static>>> {
let mut certificates = Vec::default();
for certificate in rustls_pemfile::certs(&mut pem.as_ref()) {
certificates.push(certificate?);
}
Ok(certificates)
}
pub fn parse_private_key_pem(pem: &[u8]) -> io::Result<PrivateKeyDer<'static>> {
match rustls_pemfile::private_key(&mut pem.as_ref())? {
Some(private_key) => Ok(private_key),
None => Err(io::Error::other("no private key in PEM")),
}
}
pub fn get_signing_key_from_pem(pem: &[u8]) -> io::Result<Arc<dyn SigningKey>> {
any_supported_type(&parse_private_key_pem(pem)?).map_err(io::Error::other)
}