pub fn write_to(plain: &[u8], path: &Path, key: &Key, associated_data: &[u8]) -> crate::Result<()> {
    // TODO: if path exists and is a symlink, resolve it and then append the salt
    // TODO: if the sibling tempfile isn't writeable (e.g. directory permissions), write to

    let compressed_plain = compress(plain);

    let mut salt = [0u8; 6];
    rand::fill(&mut salt)?;

    let mut s = path.as_os_str().to_os_string();
    s.push(".");
    s.push(hex::encode(salt));
    let tmp = Path::new(&s);

    let mut f = OpenOptions::new().write(true).create_new(true).open(tmp)?;
    write(&compressed_plain, &mut f, key, associated_data)?;
    f.sync_all()?;

    rename(tmp, path)?;

    Ok(())
}
/// Atomically encrypt and [`write`](fn.write.html) the specified plaintext to the specified path
///
/// This is achieved by creating a temporary file in the same directory as the specified path (same
/// filename with a salted suffix). This is currently known to be problematic if the path is a
/// symlink and/or if the target path resides in a directory without user write permission.
Atomically encrypt and [`write`](fn.write.html) the specified plaintext to the specified path
This is achieved by creating a temporary file in the same directory as the specified path (same
filename with a salted suffix). This is currently known to be problematic if the path is a
symlink and/or if the target path resides in a directory without user write permission.
Atomically encrypt and [ ` write ` ] ( fn . write . html ) the specified plaintext to the specified path This is achieved by creating a temporary file in the same directory as the specified path ( same filename with a salted suffix ) . This is currently known to be problematic if the path is a symlink and / or if the target path resides in a directory without user write permission .
pub fn write_to(plain: &[u8], path: &Path, key: &Key, associated_data: &[u8]) -> crate::Result<()> {
    // TODO: if path exists and is a symlink, resolve it and then append the salt
    // TODO: if the sibling tempfile isn't writeable (e.g. directory permissions), write to
    let compressed_plain = compress(plain);
    let mut salt = [0u8; 6];
    rand::fill(&mut salt)?;
    let mut s = path.as_os_str().to_os_string();
    s.push(".");
    s.push(hex::encode(salt));
    let tmp = Path::new(&s);
    let mut f = OpenOptions::new().write(true).create_new(true).open(tmp)?;
    write(&compressed_plain, &mut f, key, associated_data)?;
    f.sync_all()?;
    rename(tmp, path)?;
    Ok(())
}
pub fn write_to ( plain : & [ u8 ] , path : & Path , key : & Key , associated_data : & [ u8 ] ) -> crate :: Result < ( ) > { // TODO: if path exists and is a symlink, resolve it and then append the salt // TODO: if the sibling tempfile isn't writeable (e.g. directory permissions), write to let compressed_plain = compress ( plain ) ; let mut salt = [ 0u8 ; 6 ] ; rand :: fill ( & mut salt ) ? ; let mut s = path . as_os_str ( ) . to_os_string ( ) ; s . push ( " " ) ; s . push ( hex :: encode ( salt ) ) ; let tmp = Path :: new ( & s ) ; let mut f = OpenOptions :: new ( ) . write ( true ) . create_new ( true ) . open ( tmp ) ? ; write ( & compressed_plain , & mut f , key , associated_data ) ? ; f . sync_all ( ) ? ; rename ( tmp , path ) ? ; Ok ( ( ) ) }
Atomically encrypt and [`write`](fn.write.html) the specified plaintext to the specified path
This is achieved by creating a temporary file in the same directory as the specified path (same
filename with a salted suffix).
Atomically encrypt and [ ` write ` ] ( fn . write . html ) the specified plaintext to the specified path This is achieved by creating a temporary file in the same directory as the specified path ( same filename with a salted suffix ) .
plain
&[u8]
path
&Path
key
&Key
associated_data
&[u8]
plain
&[u8]
path
&Path
key
&Key
associated_data
&[u8]