diff options
Diffstat (limited to 'sq')
-rw-r--r-- | sq/src/sq-usage.rs | 4 | ||||
-rw-r--r-- | sq/src/sq.rs | 37 | ||||
-rw-r--r-- | sq/src/sq_cli.rs | 5 |
3 files changed, 32 insertions, 14 deletions
diff --git a/sq/src/sq-usage.rs b/sq/src/sq-usage.rs index 05814ced..1e232f26 100644 --- a/sq/src/sq-usage.rs +++ b/sq/src/sq-usage.rs @@ -312,7 +312,7 @@ //! Retrieves a key //! //! USAGE: -//! sq keyserver get [FLAGS] [OPTIONS] <KEYID> +//! sq keyserver get [FLAGS] [OPTIONS] <QUERY> //! //! FLAGS: //! -B, --binary Don't ASCII-armor encode the OpenPGP data @@ -323,7 +323,7 @@ //! -o, --output <FILE> Sets the output file to use //! //! ARGS: -//! <KEYID> ID of the key to retrieve +//! <QUERY> Fingerprint or KeyID of the key to retrieve //! ``` //! //! ### Subcommand keyserver send diff --git a/sq/src/sq.rs b/sq/src/sq.rs index 36e57c83..266a8bd8 100644 --- a/sq/src/sq.rs +++ b/sq/src/sq.rs @@ -17,7 +17,12 @@ use sequoia_core; use sequoia_net; use sequoia_store as store; -use crate::openpgp::Result; +use openpgp::{ + Result, + Fingerprint, + KeyID, + KeyHandle, +}; use crate::openpgp::{armor, Cert}; use sequoia_autocrypt as autocrypt; use crate::openpgp::fmt::hex; @@ -425,18 +430,30 @@ fn main() -> Result<()> { match m.subcommand() { ("get", Some(m)) => { - let keyid = m.value_of("keyid").unwrap(); - let id = keyid.parse(); - if id.is_err() { - eprintln!("Malformed key ID: {:?}\n\ - (Note: only long Key IDs are supported.)", - keyid); - exit(1); + let query = m.value_of("query").unwrap(); + + let handle: Option<KeyHandle> = { + let q_fp = query.parse::<Fingerprint>(); + let q_id = query.parse::<KeyID>(); + if let Ok(Fingerprint::V4(_)) = q_fp { + q_fp.ok().map(Into::into) + } else if let Ok(KeyID::V4(_)) = q_id { + q_fp.ok().map(Into::into) + } else { + None + } + }; + + if handle.is_none() { + Err(anyhow::anyhow!( + "Malformed key handle: {:?}\n\ + (Note: only Fingerprints long KeyIDs are \ + supported.)", query))?; } - let id = id.unwrap(); + let handle = handle.unwrap(); let mut output = create_or_stdout(m.value_of("output"), force)?; - let cert = rt.block_on(ks.get(&id)) + let cert = rt.block_on(ks.get(handle)) .context("Failed to retrieve key")?; if ! m.is_present("binary") { cert.armored().serialize(&mut output) diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs index 5bb5f80b..c4c8fd73 100644 --- a/sq/src/sq_cli.rs +++ b/sq/src/sq_cli.rs @@ -302,9 +302,10 @@ pub fn build() -> App<'static, 'static> { .long("binary") .short("B") .help("Don't ASCII-armor encode the OpenPGP data")) - .arg(Arg::with_name("keyid").value_name("KEYID") + .arg(Arg::with_name("query").value_name("QUERY") .required(true) - .help("ID of the key to retrieve"))) + .help("Fingerprint or KeyID of the key \ + to retrieve"))) .subcommand(SubCommand::with_name("send") .about("Sends a key") .arg(Arg::with_name("input").value_name("FILE") |