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

Method from_file

nodedb-wal/src/crypto.rs:157–171  ·  view source on GitHub ↗

Load key from a file (must contain exactly 32 bytes). Before reading, the file is checked for: - No symlinks (TOCTOU / path-traversal risk). - Regular file (not a device, FIFO, or directory). - Unix: no group or world access bits (`mode & 0o077 == 0`). - Unix: file owner matches the current process UID.

(path: &std::path::Path)

Source from the content-addressed store, hash-verified

155 /// - Unix: no group or world access bits (`mode & 0o077 == 0`).
156 /// - Unix: file owner matches the current process UID.
157 pub fn from_file(path: &std::path::Path) -> Result<Self> {
158 check_key_file_wal(path)?;
159 let key_bytes = std::fs::read(path).map_err(WalError::Io)?;
160 if key_bytes.len() != 32 {
161 return Err(WalError::EncryptionError {
162 detail: format!(
163 "encryption key must be exactly 32 bytes, got {}",
164 key_bytes.len()
165 ),
166 });
167 }
168 let mut key_arr = zeroize::Zeroizing::new([0u8; 32]);
169 key_arr.copy_from_slice(&key_bytes);
170 Self::from_bytes(&key_arr)
171 }
172
173 /// Encrypt a payload. Returns ciphertext + auth_tag (16 bytes appended).
174 ///

Callers

nothing calls this directly

Calls 3

check_key_file_walFunction · 0.85
readFunction · 0.50
lenMethod · 0.45

Tested by

no test coverage detected