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)
| 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 | /// |
nothing calls this directly
no test coverage detected