MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / load_key

Function load_key

chirpstack/src/helpers/tls.rs:40–57  ·  view source on GitHub ↗
(key_file: &str)

Source from the content-addressed store, hash-verified

38}
39
40pub async fn load_key(key_file: &str) -> Result<PrivateKeyDer<'static>> {
41 let key_s = fs::read_to_string(key_file)
42 .await
43 .context("Read private key")?;
44 let key_s = private_key_to_pkcs8(&key_s)?;
45 let mut key_b = key_s.as_bytes();
46 let mut keys = rustls_pemfile::pkcs8_private_keys(&mut key_b);
47 if let Some(key) = keys.next() {
48 match key {
49 Ok(v) => return Ok(PrivateKeyDer::Pkcs8(v.clone_key())),
50 Err(e) => {
51 return Err(anyhow!("Error parsing private key, error: {}", e));
52 }
53 }
54 }
55
56 Err(anyhow!("No private key found"))
57}
58
59pub fn private_key_to_pkcs8(pem: &str) -> Result<String> {
60 if pem.contains("RSA PRIVATE KEY") {

Callers 3

newMethod · 0.85
setupFunction · 0.85
newMethod · 0.85

Calls 1

private_key_to_pkcs8Function · 0.85

Tested by

no test coverage detected