summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authororhun <orhun@archlinux.org>2021-06-04 22:06:32 +0300
committerorhun <orhun@archlinux.org>2021-06-04 22:06:32 +0300
commitee056a0c006d655ad235204232b37c84ff8af799 (patch)
treec78b8df447bc290d49c2d1d8a70b24e85c56a23e
parentd7e736d1feb85c03ce96a4d96193f1c37b131c84 (diff)
feat: Display notations of the signatures (#8)
-rw-r--r--src/app/style.rs8
-rw-r--r--src/gpg/context.rs5
-rw-r--r--src/gpg/key.rs96
3 files changed, 74 insertions, 35 deletions
diff --git a/src/app/style.rs b/src/app/style.rs
index 19d7f19..7873a3c 100644
--- a/src/app/style.rs
+++ b/src/app/style.rs
@@ -72,16 +72,16 @@ pub fn get_colored_table_row<'a>(
"m" => Style::default().fg(Color::Blue),
// GPGME_VALIDITY_FULL
"f" => Style::default().fg(Color::Magenta),
- // GPGME_VALIDITY_ULTIMATE
- "u" => Style::default().fg(Color::Green),
+ // GPGME_VALIDITY_ULTIMATE | GPGME_SIG_NOTATION_HUMAN_READABLE
+ "u" | "h" => Style::default().fg(Color::Green),
// can_sign
"s" => Style::default().fg(Color::LightGreen),
// can_certify
"c" => Style::default().fg(Color::LightBlue),
// can_encrypt
"e" => Style::default().fg(Color::Yellow),
- // can_authenticate
- "a" => Style::default().fg(Color::LightRed),
+ // can_authenticate | GPGME_SIG_NOTATION_CRITICAL
+ "a" | "!" => Style::default().fg(Color::LightRed),
_ => Style::default(),
};
colored_line.push(Span::styled(c, style))
diff --git a/src/gpg/context.rs b/src/gpg/context.rs
index 67bad1f..92aa706 100644
--- a/src/gpg/context.rs
+++ b/src/gpg/context.rs
@@ -22,8 +22,9 @@ impl GpgContext {
/// Constructs a new instance of `GpgContext`.
pub fn new(config: GpgConfig) -> Result<Self> {
let mut context = Context::from_protocol(Protocol::OpenPgp)?;
- context.set_key_list_mode(KeyListMode::LOCAL)?;
- context.set_key_list_mode(KeyListMode::SIGS)?;
+ context.set_key_list_mode(
+ KeyListMode::LOCAL | KeyListMode::SIGS | KeyListMode::SIG_NOTATIONS,
+ )?;
context.set_armor(config.armor);
context.set_offline(false);
context.set_pinentry_mode(PinentryMode::Ask)?;
diff --git a/src/gpg/key.rs b/src/gpg/key.rs
index 0356667..f15c397 100644
--- a/src/gpg/key.rs
+++ b/src/gpg/key.rs
@@ -1,5 +1,5 @@
use crate::gpg::handler;
-use gpgme::{Key, Subkey, UserId, UserIdSignature};
+use gpgme::{Key, SignatureNotation, Subkey, UserId, UserIdSignature};
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::str::FromStr;
@@ -194,44 +194,82 @@ impl GpgKey {
user_index: usize,
truncate: bool,
) -> Vec<String> {
+ let mut user_signatures = Vec::new();
let signatures = user.signatures().collect::<Vec<UserIdSignature>>();
- signatures
+ for (i, sig) in signatures.iter().enumerate() {
+ let padding = if user_count == 1 {
+ " "
+ } else if user_index == user_count - 1 {
+ " "
+ } else if user_index == 0 {
+ "│"
+ } else {
+ "│ "
+ };
+ user_signatures.push(format!(
+ " {} {}[{:x}] {} {}",
+ padding,
+ if i == signatures.len() - 1 {
+ "└─"
+ } else {
+ "├─"
+ },
+ sig.cert_class(),
+ if sig.signer_key_id() == self.inner.id() {
+ String::from("selfsig")
+ } else if truncate {
+ sig.signer_key_id().unwrap_or("[?]").to_string()
+ } else {
+ let user_id = sig.signer_user_id().unwrap_or("[-]");
+ format!(
+ "{} {}",
+ sig.signer_key_id().unwrap_or("[?]"),
+ if user_id.is_empty() { "[?]" } else { user_id }
+ )
+ },
+ handler::get_signature_time(
+ *sig,
+ if truncate { "%Y" } else { "%F" }
+ )
+ ));
+ let notations = sig.notations().collect::<Vec<SignatureNotation>>();
+ if !notations.is_empty() {
+ user_signatures.extend(self.get_signature_notations(
+ notations,
+ format!(" {} ", padding),
+ ));
+ }
+ }
+ user_signatures
+ }
+
+ /// Returns the notations of the given signature.
+ fn get_signature_notations(
+ &self,
+ notations: Vec<SignatureNotation>,
+ padding: String,
+ ) -> Vec<String> {
+ notations
.iter()
.enumerate()
- .map(|(i, sig)| {
+ .map(|(i, notation)| {
format!(
- " {} {}[{:x}] {} {}",
- if user_count == 1 {
- " "
- } else if user_index == user_count - 1 {
- " "
- } else if user_index == 0 {
- "│"
- } else {
- "│ "
- },
- if i == signatures.len() - 1 {
+ "{} {}[{}] {}={}",
+ padding,
+ if i == notations.len() - 1 {
"└─"
} else {
"├─"
},
- sig.cert_class(),
- if sig.signer_key_id() == self.inner.id() {
- String::from("selfsig")
- } else if truncate {
- sig.signer_key_id().unwrap_or("[?]").to_string()
+ if notation.is_critical() {
+ "!"
+ } else if notation.is_human_readable() {
+ "h"
} else {
- let user_id = sig.signer_user_id().unwrap_or("[-]");
- format!(
- "{} {}",
- sig.signer_key_id().unwrap_or("[?]"),
- if user_id.is_empty() { "[?]" } else { user_id }
- )
+ "?"
},
- handler::get_signature_time(
- *sig,
- if truncate { "%Y" } else { "%F" }
- )
+ notation.name().unwrap_or("?"),
+ notation.value().unwrap_or("?"),
)
})
.collect()