diff --git a/rucksack/src/command/handlers/list.rs b/rucksack/src/command/handlers/list.rs index 4ab6817..85e3131 100644 --- a/rucksack/src/command/handlers/list.rs +++ b/rucksack/src/command/handlers/list.rs @@ -218,20 +218,28 @@ pub fn keys(matches: &ArgMatches, app: &App) -> Result<()> { } pub fn passwords(matches: &ArgMatches, app: &App) -> Result<()> { - let opts = Opts { - decrypted: true, - reveal: options::reveal(matches), + let mut opts = Opts { password_history: true, ..Default::default() }; + opts.reveal = options::reveal(matches); + opts.decrypted = options::decrypt(matches); let mut results: Vec = Vec::new(); let record = query::record(app)?; + let analyzed = analyzer::analyze(record.password()); + let score = scorer::score(&analyzed).trunc() as i64; let md = record.metadata(); let mut pwd = record.password(); if !opts.reveal { pwd = hidden(); } - results.push(result::password(pwd, md.created, md.updated, md.last_used)); + results.push(result::password( + pwd, + score.to_string(), + md.created, + md.updated, + md.last_used, + )); log::debug!("history length: {}", record.history().len()); // Let's get these in order of most recent to oldest: let mut history = record.history(); @@ -243,6 +251,7 @@ pub fn passwords(matches: &ArgMatches, app: &App) -> Result<()> { } results.push(result::password( pwd, + score.to_string(), old.metadata.created, old.metadata.updated, old.metadata.last_used, diff --git a/rucksack/src/output/column.rs b/rucksack/src/output/column.rs index 0ee7aa0..de7e260 100644 --- a/rucksack/src/output/column.rs +++ b/rucksack/src/output/column.rs @@ -53,7 +53,7 @@ impl Column { } pub trait Columns { - fn new(&self, opts: &Opts) -> Vec { + fn gen(&self, opts: &Opts) -> Vec { let mut cols = self.pre(opts); cols = self.passwd(opts, cols); cols = self.status(opts, cols); diff --git a/rucksack/src/output/result.rs b/rucksack/src/output/result.rs index e0cd3de..a63dffd 100644 --- a/rucksack/src/output/result.rs +++ b/rucksack/src/output/result.rs @@ -23,9 +23,16 @@ pub fn new(id: String, name: String, url: String) -> ResultRow { // This function is used for creating results rows that are needed by // the `list passwords` command. The columns below are the only columns // needed by that command. -pub fn password(pwd: String, created: String, updated: String, last_accessed: String) -> ResultRow { +pub fn password( + pwd: String, + score: String, + created: String, + updated: String, + last_accessed: String, +) -> ResultRow { let hashmap: HashMap = HashMap::from([ (Column::Password, pwd), + (Column::Score, score), (Column::Created, created), (Column::LastUpdated, updated), (Column::LastAccessed, last_accessed), diff --git a/rucksack/src/output/table.rs b/rucksack/src/output/table.rs index bf09222..549f483 100644 --- a/rucksack/src/output/table.rs +++ b/rucksack/src/output/table.rs @@ -43,31 +43,31 @@ impl Table { fn set_columns(&mut self) { if self.opts.only_keys { - self.columns = column::ColsOnlyKey {}.new(&self.opts); + self.columns = column::ColsOnlyKey {}.gen(&self.opts); } else if self.opts.kinds { - self.columns = column::ColsOnlyKind {}.new(&self.opts); + self.columns = column::ColsOnlyKind {}.gen(&self.opts); } else if self.opts.tags { - self.columns = column::ColsOnlyTags {}.new(&self.opts); + self.columns = column::ColsOnlyTags {}.gen(&self.opts); } else if self.opts.categories { - self.columns = column::ColsOnlyCat {}.new(&self.opts); + self.columns = column::ColsOnlyCat {}.gen(&self.opts); } else if self.opts.backup_files { - self.columns = column::ColsBackupFiles {}.new(&self.opts); + self.columns = column::ColsBackupFiles {}.gen(&self.opts); } else if self.opts.group_by_name { self.opts.with_passwd = true; - self.columns = column::ColsGroupByName {}.new(&self.opts); + self.columns = column::ColsGroupByName {}.gen(&self.opts); } else if self.opts.group_by_hash { - self.columns = column::ColsGroupByHash {}.new(&self.opts); + self.columns = column::ColsGroupByHash {}.gen(&self.opts); } else if self.opts.group_by_password { - self.columns = column::ColsGroupByPasswd {}.new(&self.opts); + self.columns = column::ColsGroupByPasswd {}.gen(&self.opts); } else if self.opts.group_by_kind { - self.columns = column::ColsGroupByKind {}.new(&self.opts); + self.columns = column::ColsGroupByKind {}.gen(&self.opts); } else if self.opts.group_by_category { - self.columns = column::ColsGroupByCat {}.new(&self.opts); + self.columns = column::ColsGroupByCat {}.gen(&self.opts); } else if self.opts.password_history { self.opts.with_passwd = true; - self.columns = column::ColsPasswdHist {}.new(&self.opts); + self.columns = column::ColsPasswdHist {}.gen(&self.opts); } else { - self.columns = column::ColsDefault {}.new(&self.opts); + self.columns = column::ColsDefault {}.gen(&self.opts); } self.set_headers(); } diff --git a/tests/rucksack_dev.sh b/tests/rucksack_dev.sh index cfe7f67..c1b4abf 100755 --- a/tests/rucksack_dev.sh +++ b/tests/rucksack_dev.sh @@ -464,7 +464,7 @@ header "Show password history (revealed)" --url "https://boo.fans.co.uk" \ --category default \ --type password \ - --reveal + --reveal --decrypt header "Export password data"