use rustls_pki_types::CertificateDer;
use crate::Error;
pub fn platform_roots_with(extra_roots: &[CertificateDer<'static>]) -> Result<Vec<u8>, Error> {
let loaded = rustls_native_certs::load_native_certs();
if loaded.certs.is_empty() {
let details = loaded
.errors
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("; ");
return Err(Error::tls(format!(
"no platform root certificates could be loaded: {details}"
)));
}
for error in &loaded.errors {
tracing::warn!(%error, "skipping an unreadable platform root certificate");
}
let pems = loaded
.certs
.iter()
.chain(extra_roots)
.map(|certificate| pem::Pem::new("CERTIFICATE", certificate.as_ref()))
.collect::<Vec<_>>();
Ok(pem::encode_many(&pems).into_bytes())
}