Skip to content

Commit

Permalink
Use tempfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRobb committed Nov 5, 2020
1 parent 3d29825 commit fc014e9
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions tests/test_keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,17 @@ fn test_keygen() {
// Init
let init = Cleanup::new();

let bob_pk_path = add_prefix(BOB_PUBKEY);
let bob_sk_path = add_prefix(BOB_SECKEY);
let bob_pk_path = temp_file("bob.pub");
let bob_sk_path = temp_file("bob.sec");
let callback = || return Ok(BOB_PASSPHRASE.to_string());

if Path::new(&bob_pk_path).exists() {
remove_file(&bob_pk_path);
}
if Path::new(&bob_sk_path).exists() {
remove_file(&bob_sk_path);
}

crypt4gh::keys::generate_keys(Path::new(&bob_sk_path), Path::new(&bob_pk_path), callback, None)
.expect("Unable to generate Bob's keys");

let alice_pk_path = add_prefix(ALICE_PUBKEY);
let alice_sk_path = add_prefix(ALICE_SECKEY);
let alice_pk_path = temp_file("alice.pub");
let alice_sk_path = temp_file("alice.sec");
let callback = || return Ok(ALICE_PASSPHRASE.to_string());

if Path::new(&alice_pk_path).exists() {
remove_file(&alice_pk_path);
}
if Path::new(&alice_sk_path).exists() {
remove_file(&alice_sk_path);
}

crypt4gh::keys::generate_keys(Path::new(&alice_sk_path), Path::new(&alice_pk_path), callback, None)
.expect("Unable to generate Alice's keys");

Expand All @@ -42,9 +28,9 @@ fn test_keygen() {
.env("C4GH_PASSPHRASE", BOB_PASSPHRASE)
.arg("encrypt")
.arg("--sk")
.arg(BOB_SECKEY)
.arg(strip_prefix("bob.sec"))
.arg("--recipient_pk")
.arg(ALICE_PUBKEY)
.arg(strip_prefix("alice.pub"))
.pipe_in(TESTFILE_ABCD)
.pipe_out(&temp_file("message.c4gh"))
.succeeds();
Expand All @@ -54,7 +40,7 @@ fn test_keygen() {
.env("C4GH_PASSPHRASE", ALICE_PASSPHRASE)
.arg("decrypt")
.arg("--sk")
.arg(ALICE_SECKEY)
.arg(strip_prefix("alice.sec"))
.pipe_in(&temp_file("message.c4gh"))
.pipe_out(&temp_file("message.received"))
.succeeds();
Expand Down

0 comments on commit fc014e9

Please sign in to comment.