Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "rev" detail to default view of keys #246

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/app/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn get_colored_table_row<'a>(
line.find('[').unwrap_or_default(),
line.find(']').unwrap_or_default(),
);

row.push(
// Colorize inside the brackets to start.
if second_bracket > first_bracket + 1 {
Expand Down Expand Up @@ -149,6 +150,55 @@ pub fn get_colored_table_row<'a>(
highlight_style,
));
// Colorize inside the arrows.
} else if let (
Some(first_parenthesis),
Some(second_parenthesis),
) = (data.rfind('('), data.rfind(')'))
{
let inner = line[first_parenthesis..].to_string();

log::trace!(target: "style", "inner: {inner:?}");
let expected = [
// expired
String::from("exp"),
// revoked
String::from("rev"),
// disabled
String::from("d"),
// invalid
String::from("i"),
];
if let Some((opening_parenthesis, _)) =
data.match_indices("(").next()
{
let inner = data[(opening_parenthesis + 1)
..(opening_parenthesis + 4)]
.to_string();

if expected.contains(&inner) {
colored_line.push(Span::styled(
data[..first_parenthesis].to_string(),
highlight_style,
));
colored_line.push(Span::styled(
"(",
TuiStyle::default().fg(Color::DarkGray),
));
colored_line.push(Span::styled(
data[first_parenthesis + 1..second_parenthesis]
.to_string(),
TuiStyle::default().fg(Color::Red),
));
colored_line.push(Span::styled(
")",
TuiStyle::default().fg(Color::DarkGray),
));
colored_line.push(Span::styled(
data[second_parenthesis + 1..].to_string(),
highlight_style,
));
}
}
} else if let (Some(first_arrow), Some(second_arrow)) =
(data.rfind('<'), data.rfind('>'))
{
Expand Down
31 changes: 29 additions & 2 deletions src/gpg/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,36 @@ impl GpgKey {
) -> Vec<String> {
let mut key_info = Vec::new();
let subkeys = self.inner.subkeys().collect::<Vec<Subkey>>();
let blank = String::from("");
for (i, subkey) in subkeys.iter().enumerate() {
key_info.push(format!(
"[{}]{}{}/{}",
"[{}] {} {}{}/{}",
handler::get_subkey_flags(*subkey),
format!(
"{}",
if i != subkeys.len() - 1 {
let last = subkeys.last();
if let Some(key) = last {
if key.is_expired() {
String::from("(exp)")
} else if key.is_revoked() {
String::from("(rev)")
} else if key.is_disabled() {
String::from("(d)")
} else if key.is_invalid() {
String::from("(i)")
} else if key.is_qualified() {
String::from("(q)")
} else {
blank.to_string()
}
} else {
blank.to_string()
}
} else {
blank.to_string()
}
),
if default_key.map(|v| v.trim_start_matches("0x"))
== subkey.id().ok()
{
Expand Down Expand Up @@ -227,14 +253,15 @@ impl GpgKey {
"│ "
};
user_signatures.push(format!(
" {} {}[{:x}] {} {}",
" {} {}[{:x}] {}, {} {}",
padding,
if i == signatures.len() - 1 {
"└─"
} else {
"├─"
},
sig.cert_class(),
format!("REV: {}", sig.is_revocation()),
if sig.signer_key_id() == self.inner.id() {
String::from("selfsig")
} else if truncate {
Expand Down
Loading