MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / pem_encode

Function pem_encode

nodedb/src/control/cluster/pem_io.rs:16–31  ·  view source on GitHub ↗

PEM-encode a DER blob under the given label. The output uses the canonical 64-char line wrapping (matches `openssl` output).

(label: &str, der: &[u8])

Source from the content-addressed store, hash-verified

14/// PEM-encode a DER blob under the given label. The output uses the
15/// canonical 64-char line wrapping (matches `openssl` output).
16pub fn pem_encode(label: &str, der: &[u8]) -> String {
17 use base64::Engine;
18 let b64 = base64::engine::general_purpose::STANDARD.encode(der);
19 let mut out = String::with_capacity(b64.len() + 64);
20 out.push_str("-----BEGIN ");
21 out.push_str(label);
22 out.push_str("-----\n");
23 for chunk in b64.as_bytes().chunks(64) {
24 out.push_str(std::str::from_utf8(chunk).expect("base64 is ascii"));
25 out.push('\n');
26 }
27 out.push_str("-----END ");
28 out.push_str(label);
29 out.push_str("-----\n");
30 out
31}
32
33/// Write a DER certificate as a PEM-encoded `CERTIFICATE` block.
34///

Callers 3

write_pem_certFunction · 0.85
write_pem_private_keyFunction · 0.85
pem_wrap_is_canonicalFunction · 0.85

Calls 5

encodeMethod · 0.45
lenMethod · 0.45
as_bytesMethod · 0.45
expectMethod · 0.45
pushMethod · 0.45

Tested by 1

pem_wrap_is_canonicalFunction · 0.68