diff --git a/Cargo.lock b/Cargo.lock index 1b4c380..87e2629 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,7 @@ dependencies = [ "rand 0.7.3", "secrecy", "sha2", + "which", "x509", "x509-parser", "yubikey-piv", @@ -353,6 +354,12 @@ dependencies = [ "signature", ] +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "elliptic-curve" version = "0.8.5" @@ -1212,6 +1219,16 @@ version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +[[package]] +name = "which" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe" +dependencies = [ + "either", + "libc", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 869a7e0..69c2d7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ pcsc = "2.4" rand = "0.7" secrecy = "0.7" sha2 = "0.9" +which = "4.1" x509 = "0.2" x509-parser = "0.9" yubikey-piv = { version = "0.3", features = ["untested"] } diff --git a/src/main.rs b/src/main.rs index 0e23b99..038086e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -551,6 +551,9 @@ fn main() -> Result<(), Error> { writeln!(file, "# Recipient: {}", recipient)?; writeln!(file, "{}", stub.to_string())?; + // If `rage` binary is installed, use it in examples. Otherwise default to `age`. + let age_binary = which::which("rage").map(|_| "rage").unwrap_or("age"); + eprintln!(); eprintln!("✅ Done! This YubiKey identity is ready to go."); eprintln!(); @@ -564,10 +567,16 @@ fn main() -> Result<(), Error> { eprintln!("Here are some example things you can do with it:"); eprintln!(); eprintln!("- Encrypt a file to this identity:"); - eprintln!(" $ cat foo.txt | age -r {} -o foo.txt.age", recipient); + eprintln!( + " $ cat foo.txt | {} -r {} -o foo.txt.age", + age_binary, recipient + ); eprintln!(); eprintln!("- Decrypt a file with this identity:"); - eprintln!(" $ cat foo.txt.age | age -d -i {} > foo.txt", file_name); + eprintln!( + " $ cat foo.txt.age | {} -d -i {} > foo.txt", + age_binary, file_name + ); eprintln!(); eprintln!("- Recreate the identity file:"); eprintln!(