MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / load_key

Function load_key

crates/openshell-server/src/tls.rs:316–334  ·  view source on GitHub ↗

Load a private key from a PEM file.

(path: &Path)

Source from the content-addressed store, hash-verified

314
315/// Load a private key from a PEM file.
316fn 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.
337fn tls_ocsf_ctx() -> SandboxContext {

Callers 2

build_server_configFunction · 0.85

Calls

no outgoing calls

Tested by 1