Load a private key from a PEM file.
(path: &Path)
| 314 | |
| 315 | /// Load a private key from a PEM file. |
| 316 | fn load_key(path: &Path) -> Result<PrivateKeyDer<'static>> { |
| 317 | let file = File::open(path).map_err(|e| Error::tls(format!("failed to open key file: {e}")))?; |
| 318 | let mut reader = BufReader::new(file); |
| 319 | |
| 320 | loop { |
| 321 | let item = rustls_pemfile::read_one(&mut reader) |
| 322 | .map_err(|e| Error::tls(format!("failed to parse key file: {e}")))?; |
| 323 | |
| 324 | match item { |
| 325 | Some(rustls_pemfile::Item::Pkcs1Key(key)) => return Ok(key.into()), |
| 326 | Some(rustls_pemfile::Item::Pkcs8Key(key)) => return Ok(key.into()), |
| 327 | Some(rustls_pemfile::Item::Sec1Key(key)) => return Ok(key.into()), |
| 328 | None => break, |
| 329 | _ => {} |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | Err(Error::tls("no private key found in file")) |
| 334 | } |
| 335 | |
| 336 | /// Build an OCSF context for gateway-level (non-sandbox) events. |
| 337 | fn tls_ocsf_ctx() -> SandboxContext { |
no outgoing calls