Return root certificates, optionally with the provided ca_file appended.
(ca_file: Option<String>)
| 7 | |
| 8 | // Return root certificates, optionally with the provided ca_file appended. |
| 9 | pub fn get_root_certs(ca_file: Option<String>) -> Result<rustls::RootCertStore> { |
| 10 | let mut roots = rustls::RootCertStore::empty(); |
| 11 | for cert in rustls_native_certs::load_native_certs().certs { |
| 12 | roots.add(cert)?; |
| 13 | } |
| 14 | |
| 15 | if let Some(ca_file) = &ca_file { |
| 16 | let f = File::open(ca_file).context("Open CA certificate")?; |
| 17 | let mut reader = BufReader::new(f); |
| 18 | let certs = rustls_pemfile::certs(&mut reader); |
| 19 | for cert in certs.flatten() { |
| 20 | roots.add(cert)?; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | Ok(roots) |
| 25 | } |
| 26 | |
| 27 | pub async fn load_cert(cert_file: &str) -> Result<Vec<CertificateDer<'static>>> { |
| 28 | let cert_s = fs::read_to_string(cert_file) |
no outgoing calls
no test coverage detected