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

Function write_pem_cert

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

Write a DER certificate as a PEM-encoded `CERTIFICATE` block. The write is durable: bytes go to a sibling tmp file that is fsynced before being renamed over `path`, and the parent directory is fsynced after the rename. A power loss that interrupts the write leaves either the old cert intact or the new cert fully present — never a zero-byte file.

(path: &Path, der: &[u8])

Source from the content-addressed store, hash-verified

38/// the old cert intact or the new cert fully present — never a zero-byte
39/// file.
40pub fn write_pem_cert(path: &Path, der: &[u8]) -> io::Result<()> {
41 let tmp = tmp_path(path);
42 let pem = pem_encode("CERTIFICATE", der);
43 nodedb_wal::segment::atomic_write_fsync(&tmp, path, pem.as_bytes()).map_err(io::Error::other)
44}
45
46/// Write a DER private key as a PEM-encoded `PRIVATE KEY` block and
47/// tighten the file mode to 0600 (no-op on non-Unix). Same durability

Callers 1

Calls 4

tmp_pathFunction · 0.85
pem_encodeFunction · 0.85
atomic_write_fsyncFunction · 0.85
as_bytesMethod · 0.45

Tested by 1