Skip to main content

write_secret_exclusive

Function write_secret_exclusive 

Source
pub fn write_secret_exclusive(
    dir: &Path,
    name: &str,
    value: &[u8],
) -> Result<bool>
Expand description

Write a secret only if the file does not already exist (atomic O_EXCL).

Returns Ok(true) if the file was created, Ok(false) if it already existed (another process won the race). This eliminates the TOCTOU race between checking if a key exists and generating a new one.