1use {
2 rustls::{crypto::aws_lc_rs::sign::*, sign::*},
3 rustls_pki_types::*,
4 std::{io, sync::*},
5};
6
7pub fn certified_key_from_pem(certificates_pem: &[u8], private_key_pem: &[u8]) -> io::Result<CertifiedKey> {
9 let certificates = parse_certificates_pem(certificates_pem)?;
10 let signing_key = get_signing_key_from_pem(private_key_pem)?;
11 Ok(CertifiedKey { cert: certificates, key: signing_key, ocsp: None })
12}
13
14pub fn parse_certificates_pem(pem: &[u8]) -> io::Result<Vec<CertificateDer<'static>>> {
18 let mut certificates = Vec::new();
19 for certificate in rustls_pemfile::certs(&mut pem.as_ref()) {
20 certificates.push(certificate?);
21 }
22 Ok(certificates)
23}
24
25pub fn parse_private_key_pem(pem: &[u8]) -> io::Result<PrivateKeyDer<'static>> {
31 match rustls_pemfile::private_key(&mut pem.as_ref())? {
35 Some(private_key) => Ok(private_key),
36 None => Err(io::Error::other("no private key in PEM")),
37 }
38}
39
40pub fn get_signing_key_from_pem(pem: &[u8]) -> io::Result<Arc<dyn SigningKey>> {
44 any_supported_type(&parse_private_key_pem(pem)?).map_err(io::Error::other)
45}