Add example commands to end of TUI

Closes str4d/age-plugin-yubikey#25.
This commit is contained in:
Jack Grigg
2021-04-26 23:13:05 +12:00
parent c230d93726
commit 2a013fc018
+39 -11
View File
@@ -371,7 +371,7 @@ fn main() -> Result<(), Error> {
}) })
.collect(); .collect();
let (stub, recipient, metadata) = { let ((stub, recipient, metadata), is_new) = {
let (slot_index, slot) = loop { let (slot_index, slot) = loop {
match Select::new() match Select::new()
.with_prompt("🕳️ Select a slot for your age identity") .with_prompt("🕳️ Select a slot for your age identity")
@@ -407,7 +407,7 @@ fn main() -> Result<(), Error> {
let metadata = let metadata =
util::Metadata::extract(&mut yubikey, slot, &cert, true).unwrap(); util::Metadata::extract(&mut yubikey, slot, &cert, true).unwrap();
(stub, recipient, metadata) ((stub, recipient, metadata), false)
} else { } else {
return Ok(()); return Ok(());
} }
@@ -472,15 +472,18 @@ fn main() -> Result<(), Error> {
.interact()? .interact()?
{ {
eprintln!(); eprintln!();
builder::IdentityBuilder::new(Some(slot)) (
.with_name(match name { builder::IdentityBuilder::new(Some(slot))
s if s.is_empty() => flags.name, .with_name(match name {
s => Some(s), s if s.is_empty() => flags.name,
}) s => Some(s),
.with_pin_policy(Some(pin_policy)) })
.with_touch_policy(Some(touch_policy)) .with_pin_policy(Some(pin_policy))
.force(flags.force) .with_touch_policy(Some(touch_policy))
.build(&mut yubikey)? .force(flags.force)
.build(&mut yubikey)?,
true,
)
} else { } else {
return Ok(()); return Ok(());
} }
@@ -519,6 +522,31 @@ fn main() -> Result<(), Error> {
writeln!(file, "# Recipient: {}", recipient)?; writeln!(file, "# Recipient: {}", recipient)?;
writeln!(file, "{}", stub.to_string())?; writeln!(file, "{}", stub.to_string())?;
eprintln!();
eprintln!("✅ Done! This YubiKey identity is ready to go.");
eprintln!();
if is_new {
eprintln!("🔑 Here's your shiny new YubiKey recipient:");
} else {
eprintln!("🔑 Here's the corresponding YubiKey recipient:");
}
eprintln!(" {}", recipient);
eprintln!();
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!();
eprintln!("- Decrypt a file with this identity:");
eprintln!(" $ cat foo.txt.age | age -d -i {} > foo.txt", file_name);
eprintln!();
eprintln!("- Recreate the identity file:");
eprintln!(
" $ age-plugin-yubikey -i --serial {} --slot {} > {}",
stub.serial,
util::slot_to_ui(&stub.slot),
file_name,
);
eprintln!(); eprintln!();
eprintln!("💭 Remember: everything breaks, have a backup plan for when this YubiKey does."); eprintln!("💭 Remember: everything breaks, have a backup plan for when this YubiKey does.");