pub fn transform_file<Scheme: UpEnc>(k1: Scheme::K, k2: Option<Scheme::K>, inpath: &PathBuf, operation: &str) -> PathBuf {
    let outpath = get_tmp_fname("upenc");

    match operation {
        "encrypt" => {
            // Plaintext file is inpath
            let mut pt_file = open_file(inpath);

            // Ciphertext path is split into two:
            // ${outpath}_hdr, ${outpath}_body
            let ct_hdr_path = extend_path(&outpath, "_hdr");
            let ct_path = extend_path(&outpath, "_body");
            // print!("ct header: {:?} ct path: {:?}", ct_hdr_path, ct_path);
            let mut ct_hdr = open_file(&ct_hdr_path);
            let mut ct_body = open_file(&ct_path);

            Scheme::encrypt(k1, &mut pt_file, &mut ct_hdr, &mut ct_body).unwrap()

        },
        "decrypt" => {
            let mut pt_file = open_file(&outpath);

            let ct_hdr_path = extend_path(inpath, "_hdr");
            let ct_path = extend_path(inpath, "_body");

            let mut ct_hdr = open_file(&ct_hdr_path);
            let mut ct_body = open_file(&ct_path);

            let res = Scheme::decrypt(k1, &mut ct_hdr, &mut ct_body, &mut pt_file);
            if res.is_err() {
                println!("{:?}", res);
            }
        },
        "rekeygen" => {
            let rk_path = extend_path(inpath, "_rk");
            let ct_hdr_path = extend_path(inpath, "_hdr");

            let mut rkfile = open_file(&rk_path);
            let mut ctfile = open_file(&ct_hdr_path);

            Scheme::rekeygen(k1, k2.unwrap(), &mut ctfile, &mut rkfile).unwrap();
        }
        "reencrypt" => {
            // Input ciphertext files
            let ct_hdr_path = extend_path(inpath, "_hdr");
            let ct_path = extend_path(inpath, "_body");
            let rk_path = extend_path(inpath, "_rk");

            let mut rk_file = open_file(&rk_path);
            let mut ct_hdr = open_file(&ct_hdr_path);
            let mut ct_body = open_file(&ct_path);

            // Output ciphertext files
            let new_ct_hdr_path = extend_path(&outpath, "_hdr");
            let new_ct_path = extend_path(&outpath, "_body");

            let mut ct_hdr2 = open_file(&new_ct_hdr_path);
            let mut ct_body2 = open_file(&new_ct_path);
            
            Scheme::reencrypt(&mut rk_file, &mut ct_hdr, &mut ct_body, &mut ct_hdr2, &mut ct_body2).unwrap();
        }
        _ => panic!("Unknown operation: {}", operation)
    };
    outpath
}
// Runs a file operation (encrypt, decrypt, update) on the 
// in path. Returns the path of the newly created file that holds
// the result.
Runs a file operation (encrypt, decrypt, update) on the
in path. Returns the path of the newly created file that holds
the result.
Runs a file operation ( encrypt decrypt update ) on the in path . Returns the path of the newly created file that holds the result .
pub fn transform_file<Scheme: UpEnc>(k1: Scheme::K, k2: Option<Scheme::K>, inpath: &PathBuf, operation: &str) -> PathBuf {
    let outpath = get_tmp_fname("upenc");
    match operation {
        "encrypt" => {
            // Plaintext file is inpath
            let mut pt_file = open_file(inpath);
            // Ciphertext path is split into two:
            // ${outpath}_hdr, ${outpath}_body
            let ct_hdr_path = extend_path(&outpath, "_hdr");
            let ct_path = extend_path(&outpath, "_body");
            // print!("ct header: {:?} ct path: {:?}", ct_hdr_path, ct_path);
            let mut ct_hdr = open_file(&ct_hdr_path);
            let mut ct_body = open_file(&ct_path);
            Scheme::encrypt(k1, &mut pt_file, &mut ct_hdr, &mut ct_body).unwrap()
        },
        "decrypt" => {
            let mut pt_file = open_file(&outpath);
            let ct_hdr_path = extend_path(inpath, "_hdr");
            let ct_path = extend_path(inpath, "_body");
            let mut ct_hdr = open_file(&ct_hdr_path);
            let mut ct_body = open_file(&ct_path);
            let res = Scheme::decrypt(k1, &mut ct_hdr, &mut ct_body, &mut pt_file);
            if res.is_err() {
                println!("{:?}", res);
            }
        },
        "rekeygen" => {
            let rk_path = extend_path(inpath, "_rk");
            let ct_hdr_path = extend_path(inpath, "_hdr");
            let mut rkfile = open_file(&rk_path);
            let mut ctfile = open_file(&ct_hdr_path);
            Scheme::rekeygen(k1, k2.unwrap(), &mut ctfile, &mut rkfile).unwrap();
        }
        "reencrypt" => {
            // Input ciphertext files
            let ct_hdr_path = extend_path(inpath, "_hdr");
            let ct_path = extend_path(inpath, "_body");
            let rk_path = extend_path(inpath, "_rk");
            let mut rk_file = open_file(&rk_path);
            let mut ct_hdr = open_file(&ct_hdr_path);
            let mut ct_body = open_file(&ct_path);
            // Output ciphertext files
            let new_ct_hdr_path = extend_path(&outpath, "_hdr");
            let new_ct_path = extend_path(&outpath, "_body");
            let mut ct_hdr2 = open_file(&new_ct_hdr_path);
            let mut ct_body2 = open_file(&new_ct_path);
            Scheme::reencrypt(&mut rk_file, &mut ct_hdr, &mut ct_body, &mut ct_hdr2, &mut ct_body2).unwrap();
        }
        _ => panic!("Unknown operation: {}", operation)
    };
    outpath
}
pub fn transform_file < Scheme : UpEnc > ( k1 : Scheme :: K , k2 : Option < Scheme :: K > , inpath : & PathBuf , operation : & str ) -> PathBuf { let outpath = get_tmp_fname ( " " ) ; match operation { " " => { // Plaintext file is inpath let mut pt_file = open_file ( inpath ) ; // Ciphertext path is split into two: // ${outpath}_hdr, ${outpath}_body let ct_hdr_path = extend_path ( & outpath , " " ) ; let ct_path = extend_path ( & outpath , " " ) ; // print!("ct header: {:?} ct path: {:?}", ct_hdr_path, ct_path); let mut ct_hdr = open_file ( & ct_hdr_path ) ; let mut ct_body = open_file ( & ct_path ) ; Scheme :: encrypt ( k1 , & mut pt_file , & mut ct_hdr , & mut ct_body ) . unwrap ( ) } , " " => { let mut pt_file = open_file ( & outpath ) ; let ct_hdr_path = extend_path ( inpath , " " ) ; let ct_path = extend_path ( inpath , " " ) ; let mut ct_hdr = open_file ( & ct_hdr_path ) ; let mut ct_body = open_file ( & ct_path ) ; let res = Scheme :: decrypt ( k1 , & mut ct_hdr , & mut ct_body , & mut pt_file ) ; if res . is_err ( ) { println ! ( " " res ) ; } } , " " => { let rk_path = extend_path ( inpath , " " ) ; let ct_hdr_path = extend_path ( inpath , " " ) ; let mut rkfile = open_file ( & rk_path ) ; let mut ctfile = open_file ( & ct_hdr_path ) ; Scheme :: rekeygen ( k1 , k2 . unwrap ( ) , & mut ctfile , & mut rkfile ) . unwrap ( ) ; } " " => { // Input ciphertext files let ct_hdr_path = extend_path ( inpath , " " ) ; let ct_path = extend_path ( inpath , " " ) ; let rk_path = extend_path ( inpath , " " ) ; let mut rk_file = open_file ( & rk_path ) ; let mut ct_hdr = open_file ( & ct_hdr_path ) ; let mut ct_body = open_file ( & ct_path ) ; // Output ciphertext files let new_ct_hdr_path = extend_path ( & outpath , " " ) ; let new_ct_path = extend_path ( & outpath , " " ) ; let mut ct_hdr2 = open_file ( & new_ct_hdr_path ) ; let mut ct_body2 = open_file ( & new_ct_path ) ; Scheme :: reencrypt ( & mut rk_file , & mut ct_hdr , & mut ct_body , & mut ct_hdr2 , & mut ct_body2 ) . unwrap ( ) ; } _ => panic ! ( " " operation ) } ; outpath }
Runs a file operation (encrypt, decrypt, update) on the
in path.
Runs a file operation ( encrypt decrypt update ) on the in path .
k1
Scheme::K
k2
Option<Scheme::K>
inpath
&PathBuf
operation
&str
k1
Scheme::K
k2
Option<Scheme::K>
inpath
&PathBuf
operation
&str