Skip to content

Commit

Permalink
add a -p option in keygen to save the public key
Browse files Browse the repository at this point in the history
  • Loading branch information
glehmann committed Feb 4, 2024
1 parent 01ca76e commit 7235042
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ $ yage --completion fish > ~/.config/fish/completions/yage.fish
First generate a new age key pair:

```sh
$ yage keygen -o prod.key
$ yage keygen -o prod.key -p prod.pub
Public key: age15eesfkh778yljxzgwdq5vaqmmchg5py480vplsymzzqf0dwe5gnqrexdq6
```

Expand All @@ -112,7 +112,6 @@ AGE-SECRET-KEY-1EZEU9RUTW3K5GV98ER6RHMS73QJNQ37ARWG6MWHXM4JP8FVD3A9QK2DD70
The public key could be committed to a git repository:

```sh
$ yage pubkey -K prod.key -o prod.pub
$ git add prod.pub
$ git commit -m "Add prod public key"
```
Expand Down
1 change: 1 addition & 0 deletions doc/CommandLineHelp.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ The key is written in the age format, which is compatible with the age tool.
* `-o`, `--output <OUTPUT>` — The output path to the private key file

Default value: `-`
* `-p`, `--public <PUBLIC>` — The output path to the public key file



Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub struct KeygenArgs {
/// The private key is written to the standard output by default.
#[clap(short, long, default_value = "-")]
pub output: PathBuf,

/// The output path to the public key file
#[clap(short, long)]
pub public: Option<PathBuf>,
}

/// Convert private age keys to their public key
Expand Down
8 changes: 6 additions & 2 deletions src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ use crate::error::{IOResultExt, Result};
use crate::util::stdout_or_file;

pub fn keygen(args: &KeygenArgs) -> Result<()> {
let mut output = stdout_or_file(&args.output)?;
let key = Identity::generate();
info!("Public key: {}", key.to_public());
let mut output = stdout_or_file(&args.output)?;
writeln!(output, "{}", key.to_string().expose_secret()).path_ctx(&args.output)?;
info!("Public key: {}", key.to_public());
if let Some(ref public) = args.public {
let mut output = stdout_or_file(public)?;
writeln!(output, "{}", key.to_public()).path_ctx(public)?;
}
Ok(())
}

0 comments on commit 7235042

Please sign in to comment.