Skip to content

Commit

Permalink
rage-keygen: Print recipient to terminal after writing identity file
Browse files Browse the repository at this point in the history
This ensures that if we cannot write the identity file (for example, if
the file already exists), we don't output a recipient that cannot be
used (because its identity was lost).
  • Loading branch information
str4d committed Jan 7, 2024
1 parent 56e3ff0 commit 47ccdc2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions rage/src/bin/rage-keygen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ fn main() -> Result<(), error::Error> {
let pk = sk.to_public();

(|| {
if !output.is_terminal() {
eprintln!("{}: {}", fl!("tty-pubkey"), pk);
}

writeln!(
output,
"# {}: {}",
fl!("identity-file-created"),
chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true)
)?;
writeln!(output, "# {}: {}", fl!("identity-file-pubkey"), pk)?;
writeln!(output, "{}", sk.to_string().expose_secret())
writeln!(output, "{}", sk.to_string().expose_secret())?;

if !output.is_terminal() {
eprintln!("{}: {}", fl!("tty-pubkey"), pk);
}

Ok(())
})()
.map_err(error::Error::FailedToWriteOutput)
}
Expand Down

0 comments on commit 47ccdc2

Please sign in to comment.