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])
| 38 | /// the old cert intact or the new cert fully present — never a zero-byte |
| 39 | /// file. |
| 40 | pub 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 |