// Encrypt or decrypt according to arguments.
Encrypt or decrypt according to arguments.
Encrypt or decrypt according to arguments .
fn run(
    action: des::Action,
    args: &ArgMatches,
    f: &dyn Fn(Vec<u64>, u64, &mut Box<dyn Cipher>) -> Vec<u64>,
) -> Result<(), io::Error> {
    let key: u64 = match read_key(&args) {
        Err(e) => {
            eprintln!("Error getting the key: {}", e);
            return Err(e);
        }
        Ok(k) => k,
    };
    let mut mode = get_cipher_mode(args);
    let reader = match ChunkReader::new(action, args.value_of("in").unwrap()) {
        Err(e) => {
            eprintln!("Error while trying to open input file: {}", e);
            return Err(e);
        }
        Ok(r) => r,
    };
    let mut writer = match ChunkWriter::new(action, args.value_of("out").unwrap()) {
        Err(e) => {
            eprintln!("Error while trying to open output file: {}", e);
            return Err(e);
        }
        Ok(w) => w,
    };
    for chunk in reader {
        let (processed, is_last_chunk) = match chunk {
            Err(e) => {
                eprintln!("Error while reading the input file: {}", e);
                return Err(e);
            }
            Ok(chunk) => (f(chunk.data, key, &mut mode), chunk.is_last_chunk),
        };
        match writer.write(&processed, is_last_chunk) {
            Err(e) => {
                eprintln!("Could not write to output file: {}", e);
                return Err(e);
            }
            Ok(_) => {}
        }
    }
    return Ok(());
}
fn run ( action : des :: Action , args : & ArgMatches , f : & dyn Fn ( Vec < u64 > , u64 , & mut Box < dyn Cipher > ) -> Vec < u64 > , ) -> Result < ( ) , io :: Error > { let key : u64 = match read_key ( & args ) { Err ( e ) => { eprintln ! ( " " e ) ; return Err ( e ) ; } Ok ( k ) => k , } ; let mut mode = get_cipher_mode ( args ) ; let reader = match ChunkReader :: new ( action , args . value_of ( " " ) . unwrap ( ) ) { Err ( e ) => { eprintln ! ( " " e ) ; return Err ( e ) ; } Ok ( r ) => r , } ; let mut writer = match ChunkWriter :: new ( action , args . value_of ( " " ) . unwrap ( ) ) { Err ( e ) => { eprintln ! ( " " e ) ; return Err ( e ) ; } Ok ( w ) => w , } ; for chunk in reader { let ( processed , is_last_chunk ) = match chunk { Err ( e ) => { eprintln ! ( " " e ) ; return Err ( e ) ; } Ok ( chunk ) => ( f ( chunk . data , key , & mut mode ) , chunk . is_last_chunk ) , } ; match writer . write ( & processed , is_last_chunk ) { Err ( e ) => { eprintln ! ( " " e ) ; return Err ( e ) ; } Ok ( _ ) => { } } } return Ok ( ( ) ) ; }
Encrypt or decrypt according to arguments.
Encrypt or decrypt according to arguments .
action
des::Action
args
&ArgMatches
f
&dyn Fn(Vec<u64>, u64, &mut Box<dyn Cipher>) -> Vec<u64>