Skip to content

Commit

Permalink
Added initial support for hashes.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Dec 15, 2023
1 parent 3f0c17e commit 059aeca
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rucksack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ anyhow = "1.0"
clap = { version = "4.0", features = ["string", "env"] }
clap_complete = "4.0"
confyg = "0.2"
digest = "0.10.7"
log = "0.4"
passwords = "3.1"
prettytable-rs = "0.10.0"
rpassword = "7.1"
secrecy = "0.8"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
twyg = "0.2"
versions = "6.0.0"

Expand Down
14 changes: 14 additions & 0 deletions rucksack/src/command/handlers/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
use anyhow::Result;
use clap::ArgMatches;
use passwords::{analyzer, scorer};
use sha2::{Digest, Sha256};

use rucksack_db::records;
use rucksack_db::Status;
Expand Down Expand Up @@ -331,6 +332,19 @@ fn process_records(matches: &ArgMatches, app: &App, mut opts: Opts) -> Result<()
let entry = groups.entry(record.password()).or_default();
entry.push(result.clone());
}
// Hashes
if !opts.hash_fields.is_empty() && !opts.built_hashes {
let mut vals: Vec<String> = vec![];
for col in opts.hash_fields.iter() {
let val = result.get(col).unwrap().to_owned();
vals.push(val);
}
let hash = format!(
"{:x}",
Sha256::new().chain_update(vals.join(":")).finalize()
);
result.add(Column::Hash, hash);
}
results.push(result);
}
sort(&mut results, sort_by);
Expand Down
1 change: 1 addition & 0 deletions rucksack/src/output/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub enum Column {
Category,
Count,
Created,
Hash,
Id,
Imported,
Key,
Expand Down
5 changes: 5 additions & 0 deletions rucksack/src/output/option.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use super::Column;

#[derive(Clone, Debug, Default)]
pub struct Opts {
pub backup_files: bool,
pub built_hashes: bool,
pub categories: bool,
pub decrypted: bool,
pub group_by_category: bool,
pub group_by_kind: bool,
pub group_by_name: bool,
pub group_by_password: bool,
pub group_by_hash: bool,
pub hash_fields: Vec<Column>,
pub kinds: bool,
pub latest_only: bool,
pub only_deleted: bool,
Expand Down
5 changes: 5 additions & 0 deletions rucksack/src/output/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ pub fn category(cat: String) -> ResultRow {
ResultRow { hashmap }
}

pub fn hash(hash: String) -> ResultRow {
let hashmap: HashMap<Column, String> = HashMap::from([(Column::Hash, hash)]);
ResultRow { hashmap }
}

pub fn kind(kind: String) -> ResultRow {
let hashmap: HashMap<Column, String> = HashMap::from([(Column::Kind, kind)]);
ResultRow { hashmap }
Expand Down

0 comments on commit 059aeca

Please sign in to comment.