Skip to content

Commit

Permalink
feat: suppress gpg output
Browse files Browse the repository at this point in the history
  • Loading branch information
jost-s committed Apr 13, 2024
1 parent aac61fb commit 99caa9a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,14 @@ pub fn read_decrypted_key_from_file(
.arg("--decrypt")
.arg(&file_path)
.stdout(Stdio::piped())
.stdin(Stdio::inherit())
.stderr(Stdio::piped())
.output()
.map_err(|err| format!("Error running encryption command {GPG_COMMAND} - {err}"))?;
// gpg encryption info is written to stderr
// only display if it contains error text
// probably never, in error case above command would fail
if !output.stderr.is_empty() {
if !output.status.success() {
let err_output = String::from_utf8(output.stderr)
.map_err(|err| format!("Error parsing {GPG_COMMAND} error message - {err}"))?;
if err_output.contains("error") {
eprintln!("Error reading decrypted key from file - {}", err_output);
}
return Err(err_output);
}
let decrypted_key = String::from_utf8(output.stdout)
.map_err(|err| format!("Error reading decrypted key from file - {}", err))?;
Expand Down Expand Up @@ -266,6 +262,10 @@ mod tests {
// encrypt key and write to file
let identifier = "test_identifier";
let key = "1234567890";
println!(
"dir path {:?} totp_dir {:?} identifier {identifier} key {key}",
dir_path, totp_dir
);
write_encrypted_key_to_file(&dir_path, &totp_dir, identifier, key).unwrap();

// decrypt from encrypted file
Expand Down

0 comments on commit 99caa9a

Please sign in to comment.