pub fn encrypt_snapshot(input: Vec<u8>, out: &mut File, password: &[u8]) -> crate::Result<()> {
    // convert vector to slice
    let mut slice = input.as_slice();
    // setup buffer
    let mut buf = [0; CHUNK_SIZE];
    // get input length
    let mut input_len = slice.len();

    // write the signature to the file first.
    out.write_all(&SIGN)?;
    out.write_all(&VERSION)?;

    // get the salt and write it to the file.
    let salt = generate_salt()?;
    out.write_all(&salt.0)?;

    // derive a key from the password and salt.
    let key = derive_key_from_password(password, &salt)?;
    // create the stream and header from the key.
    let (mut stream, header) = create_stream(&key)?;

    // write the header to the file.
    out.write_all(&header.0)?;

    loop {
        // loop through the data and write it to the stream and then to the file.
        match slice.read(&mut buf) {
            Ok(amount_read) if amount_read > 0 => {
                input_len -= amount_read as usize;
                let tag = match input_len {
                    // when input_len reaches 0 pass Tag::Final to the stream.
                    0 => Tag::Final,
                    _ => Tag::Message,
                };
                out.write_all(
                    &stream
                        .push(&buf[..amount_read], None, tag)
                        .map_err(|_| crate::Error::SnapshotError("Failed to encrypt".into()))?,
                )?
            }
            Err(e) => return Err(crate::Error::from(e)),
            _ => break,
        }
    }

    Ok(())
}
/// encrypt an input with a password in using secretstream.
encrypt an input with a password in using secretstream.
encrypt an input with a password in using secretstream .
pub fn encrypt_snapshot(input: Vec<u8>, out: &mut File, password: &[u8]) -> crate::Result<()> {
    // convert vector to slice
    let mut slice = input.as_slice();
    // setup buffer
    let mut buf = [0; CHUNK_SIZE];
    // get input length
    let mut input_len = slice.len();
    // write the signature to the file first.
    out.write_all(&SIGN)?;
    out.write_all(&VERSION)?;
    // get the salt and write it to the file.
    let salt = generate_salt()?;
    out.write_all(&salt.0)?;
    // derive a key from the password and salt.
    let key = derive_key_from_password(password, &salt)?;
    // create the stream and header from the key.
    let (mut stream, header) = create_stream(&key)?;
    // write the header to the file.
    out.write_all(&header.0)?;
    loop {
        // loop through the data and write it to the stream and then to the file.
        match slice.read(&mut buf) {
            Ok(amount_read) if amount_read > 0 => {
                input_len -= amount_read as usize;
                let tag = match input_len {
                    // when input_len reaches 0 pass Tag::Final to the stream.
                    0 => Tag::Final,
                    _ => Tag::Message,
                };
                out.write_all(
                    &stream
                        .push(&buf[..amount_read], None, tag)
                        .map_err(|_| crate::Error::SnapshotError("Failed to encrypt".into()))?,
                )?
            }
            Err(e) => return Err(crate::Error::from(e)),
            _ => break,
        }
    }
    Ok(())
}
pub fn encrypt_snapshot ( input : Vec < u8 > , out : & mut File , password : & [ u8 ] ) -> crate :: Result < ( ) > { // convert vector to slice let mut slice = input . as_slice ( ) ; // setup buffer let mut buf = [ 0 ; CHUNK_SIZE ] ; // get input length let mut input_len = slice . len ( ) ; // write the signature to the file first. out . write_all ( & SIGN ) ? ; out . write_all ( & VERSION ) ? ; // get the salt and write it to the file. let salt = generate_salt ( ) ? ; out . write_all ( & salt . 0 ) ? ; // derive a key from the password and salt. let key = derive_key_from_password ( password , & salt ) ? ; // create the stream and header from the key. let ( mut stream , header ) = create_stream ( & key ) ? ; // write the header to the file. out . write_all ( & header . 0 ) ? ; loop { // loop through the data and write it to the stream and then to the file. match slice . read ( & mut buf ) { Ok ( amount_read ) if amount_read > 0 => { input_len -= amount_read as usize ; let tag = match input_len { // when input_len reaches 0 pass Tag::Final to the stream. 0 => Tag :: Final , _ => Tag :: Message , } ; out . write_all ( & stream . push ( & buf [ .. amount_read ] , None , tag ) . map_err ( | _ | crate :: Error :: SnapshotError ( " " . into ( ) ) ) ? , ) ? } Err ( e ) => return Err ( crate :: Error :: from ( e ) ) , _ => break , } } Ok ( ( ) ) }
encrypt an input with a password in using secretstream.
encrypt an input with a password in using secretstream .
input
Vec<u8>
out
&mut File
password
&[u8]