Skip to content

Commit

Permalink
implement pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
glehmann committed Feb 1, 2024
1 parent c0fb15b commit de74005
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Cli {
#[derive(Subcommand, Debug)]
pub enum Commands {
Keygen(KeygenArgs),
Pubkey(PubkeyArgs),
Edit(EditArgs),
Encrypt(EncryptArgs),
Decrypt(DecryptArgs),
Expand All @@ -26,6 +27,22 @@ pub enum Commands {
/// Generate a new key
#[derive(Args, Debug)]
pub struct KeygenArgs {
/// The output path to the public key file
#[clap(short, long, default_value = "-")]
pub output: PathBuf,
}

/// Convert private keys to their public key
#[derive(Args, Debug)]
pub struct PubkeyArgs {
/// Decrypt with the specified key
#[clap(env = "YAGE_KEY")]
pub keys: Vec<String>,

/// Decrypt with the key at PATH
#[clap(short = 'K', long = "key-file", name = "PATH", env = "YAGE_KEY_FILE")]
pub key_files: Vec<PathBuf>,

/// The output path to the private key file
#[clap(short, long, default_value = "-")]
pub output: PathBuf,
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod encrypt;
mod env;
mod error;
mod keygen;
mod pubkey;
mod util;

fn run() -> error::Result<()> {
Expand All @@ -21,6 +22,7 @@ fn run() -> error::Result<()> {

match cli.command.unwrap() {
Commands::Keygen(ref args) => keygen::keygen(args)?,
Commands::Pubkey(ref args) => pubkey::pubkey(args)?,
Commands::Edit(ref args) => edit::edit(args)?,
Commands::Encrypt(ref args) => encrypt::encrypt(args)?,
Commands::Decrypt(ref args) => decrypt::decrypt(args)?,
Expand Down
12 changes: 12 additions & 0 deletions src/pubkey.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::cli::PubkeyArgs;
use crate::error::{IOResultExt, Result};
use crate::util::{load_identities, stdout_or_file};

pub fn pubkey(args: &PubkeyArgs) -> Result<()> {
let keys = load_identities(&args.keys, &args.key_files)?;
let mut output = stdout_or_file(&args.output)?;
for key in keys {
writeln!(output, "{}", key.to_public()).path_ctx(&args.output)?;
}
Ok(())
}

0 comments on commit de74005

Please sign in to comment.