Load certificates from a PEM file.
(path: &Path)
| 297 | |
| 298 | /// Load certificates from a PEM file. |
| 299 | fn load_certs(path: &Path) -> Result<Vec<CertificateDer<'static>>> { |
| 300 | let file = |
| 301 | File::open(path).map_err(|e| Error::tls(format!("failed to open cert file: {e}")))?; |
| 302 | let mut reader = BufReader::new(file); |
| 303 | |
| 304 | let certs: Vec<_> = rustls_pemfile::certs(&mut reader) |
| 305 | .collect::<std::result::Result<Vec<_>, _>>() |
| 306 | .map_err(|e| Error::tls(format!("failed to parse certificates: {e}")))?; |
| 307 | |
| 308 | if certs.is_empty() { |
| 309 | return Err(Error::tls("no certificates found in file")); |
| 310 | } |
| 311 | |
| 312 | Ok(certs) |
| 313 | } |
| 314 | |
| 315 | /// Load a private key from a PEM file. |
| 316 | fn load_key(path: &Path) -> Result<PrivateKeyDer<'static>> { |