Parse certificate and private key PEM strings into a CertifiedKey
(cert_pem: &str, key_pem: &str)
| 277 | |
| 278 | /// Parse certificate and private key PEM strings into a CertifiedKey |
| 279 | fn parse_certified_key(cert_pem: &str, key_pem: &str) -> Result<CertifiedKey> { |
| 280 | let certs = CertificateDer::pem_slice_iter(cert_pem.as_bytes()) |
| 281 | .collect::<Result<Vec<_>, _>>() |
| 282 | .context("failed to parse certificate chain")?; |
| 283 | |
| 284 | if certs.is_empty() { |
| 285 | anyhow::bail!("no certificates found in PEM"); |
| 286 | } |
| 287 | |
| 288 | let key = |
| 289 | PrivateKeyDer::from_pem_slice(key_pem.as_bytes()).context("failed to parse private key")?; |
| 290 | |
| 291 | let signing_key = rustls::crypto::aws_lc_rs::sign::any_supported_type(&key) |
| 292 | .map_err(|e| anyhow::anyhow!("failed to create signing key: {:?}", e))?; |
| 293 | |
| 294 | Ok(CertifiedKey::new(certs, signing_key)) |
| 295 | } |
| 296 | |
| 297 | /// Format expiry timestamp as human-readable string |
| 298 | fn format_expiry(not_after: u64) -> String { |