fn decrypt_file(input: &mut File, output: &mut Vec<u8>, password: &[u8], salt: pwhash::Salt) -> crate::Result<()> {
    // setup header buffer and extract it from the file
    let mut header = [0u8; secretstream::HEADERBYTES];
    input.read_exact(&mut header)?;

    // generate a key from the salt and password.
    let key = derive_key_from_password(&password, &salt)?;

    // create buffer.
    let mut buf = [0u8; CHUNK_SIZE + secretstream::ABYTES];
    // get the pull stream.
    let mut stream = pull_stream(&header, &key)?;

    // iterate through the stream until its finalized.
    while stream.is_not_finalized() {
        // read the input into the buffer
        match input.read(&mut buf) {
            Ok(bytes_read) if bytes_read > 0 => {
                // pull each chunk from the stream and decrypt.
                let (decrypt, _tag) = stream.pull(&buf[..bytes_read], None).map_err(|_| {
                    crate::Error::SnapshotError("Stream pull failed, could not decrypt snapshot".into())
                })?;

                // put the vectors into the output vector.
                output.extend(&decrypt);
            }
            Err(_) => return Err(crate::Error::SnapshotError("Incorrect Password".into())),
            _ => return Err(crate::Error::SnapshotError("Decryption failed... ".into())),
        }
    }

    Ok(())
}
// logic to decrypt the file.
logic to decrypt the file.
logic to decrypt the file .
fn decrypt_file(input: &mut File, output: &mut Vec<u8>, password: &[u8], salt: pwhash::Salt) -> crate::Result<()> {
    // setup header buffer and extract it from the file
    let mut header = [0u8; secretstream::HEADERBYTES];
    input.read_exact(&mut header)?;
    // generate a key from the salt and password.
    let key = derive_key_from_password(&password, &salt)?;
    // create buffer.
    let mut buf = [0u8; CHUNK_SIZE + secretstream::ABYTES];
    // get the pull stream.
    let mut stream = pull_stream(&header, &key)?;
    // iterate through the stream until its finalized.
    while stream.is_not_finalized() {
        // read the input into the buffer
        match input.read(&mut buf) {
            Ok(bytes_read) if bytes_read > 0 => {
                // pull each chunk from the stream and decrypt.
                let (decrypt, _tag) = stream.pull(&buf[..bytes_read], None).map_err(|_| {
                    crate::Error::SnapshotError("Stream pull failed, could not decrypt snapshot".into())
                })?;
                // put the vectors into the output vector.
                output.extend(&decrypt);
            }
            Err(_) => return Err(crate::Error::SnapshotError("Incorrect Password".into())),
            _ => return Err(crate::Error::SnapshotError("Decryption failed... ".into())),
        }
    }
    Ok(())
}
fn decrypt_file ( input : & mut File , output : & mut Vec < u8 > , password : & [ u8 ] , salt : pwhash :: Salt ) -> crate :: Result < ( ) > { // setup header buffer and extract it from the file let mut header = [ 0u8 ; secretstream :: HEADERBYTES ] ; input . read_exact ( & mut header ) ? ; // generate a key from the salt and password. let key = derive_key_from_password ( & password , & salt ) ? ; // create buffer. let mut buf = [ 0u8 ; CHUNK_SIZE + secretstream :: ABYTES ] ; // get the pull stream. let mut stream = pull_stream ( & header , & key ) ? ; // iterate through the stream until its finalized. while stream . is_not_finalized ( ) { // read the input into the buffer match input . read ( & mut buf ) { Ok ( bytes_read ) if bytes_read > 0 => { // pull each chunk from the stream and decrypt. let ( decrypt , _tag ) = stream . pull ( & buf [ .. bytes_read ] , None ) . map_err ( | _ | { crate :: Error :: SnapshotError ( " " . into ( ) ) } ) ? ; // put the vectors into the output vector. output . extend ( & decrypt ) ; } Err ( _ ) => return Err ( crate :: Error :: SnapshotError ( " " . into ( ) ) ) , _ => return Err ( crate :: Error :: SnapshotError ( " " . into ( ) ) ) , } } Ok ( ( ) ) }
logic to decrypt the file.
logic to decrypt the file .
input
&mut File
output
&mut Vec<u8>
password
&[u8]
salt
pwhash::Salt