Lines
100 %
Functions
50 %
Branches
//! SSH keys tab: the user's public keys, from `list-ssh-keys`.
use ratatui::layout::Constraint;
use scripting::nomiscript::{Value, format_value};
use crate::tabs::plist::plist_text;
use crate::tabs::select_list::{SelectList, SelectRow};
/// One registered public key.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SshKeyRow {
pub id: String,
pub key_type: String,
pub fingerprint: String,
pub comment: String,
/// The day the key was added.
pub added: String,
}
/// The `list-ssh-keys` view: exactly the keys the user holds.
pub type SshKeysTab = SelectList<SshKeyRow>;
impl SelectRow for SshKeyRow {
const HEADERS: &'static [&'static str] = &["Type", "Fingerprint", "Comment", "Added"];
const WIDTHS: &'static [Constraint] = &[
Constraint::Length(12),
Constraint::Length(52),
Constraint::Fill(1),
Constraint::Length(10),
];
fn parse(plist: &Value) -> Result<Self, String> {
let malformed = || format!("malformed ssh key: {}", format_value(plist));
let text = |name| plist_text(plist, name).ok_or_else(malformed);
let created = text(":created-at")?;
Ok(Self {
id: text(":id")?,
key_type: text(":key-type")?,
fingerprint: text(":fingerprint")?,
comment: text(":name")?,
added: created.get(..10).unwrap_or(&created).to_string(),
})
fn key(&self) -> &str {
&self.fingerprint
fn has_key(&self, key: &str) -> bool {
self.fingerprint == key || self.id == key
fn cells(&self) -> Vec<String> {
vec![
self.key_type.clone(),
self.fingerprint.clone(),
self.comment.clone(),
self.added.clone(),
]
#[cfg(test)]
mod tests;