Line data Source code
1 : use camino::Utf8Path;
2 : use tokio_rustls::rustls::pki_types::{CertificateDer, PrivateKeyDer};
3 :
4 0 : pub fn load_cert_chain(filename: &Utf8Path) -> anyhow::Result<Vec<CertificateDer<'static>>> {
5 0 : let file = std::fs::File::open(filename)?;
6 0 : let mut reader = std::io::BufReader::new(file);
7 0 :
8 0 : Ok(rustls_pemfile::certs(&mut reader).collect::<Result<Vec<_>, _>>()?)
9 0 : }
10 :
11 0 : pub fn load_private_key(filename: &Utf8Path) -> anyhow::Result<PrivateKeyDer<'static>> {
12 0 : let file = std::fs::File::open(filename)?;
13 0 : let mut reader = std::io::BufReader::new(file);
14 :
15 0 : let key = rustls_pemfile::private_key(&mut reader)?;
16 :
17 0 : key.ok_or(anyhow::anyhow!(
18 0 : "no private key found in {}",
19 0 : filename.as_str(),
20 0 : ))
21 0 : }
|