🚧 Adds searching algorithm
Signed-off-by: Ash Svitan <selfsigned-ash@proton.me>
This commit is contained in:
+46
-2
@@ -41,14 +41,58 @@ fn main() -> Result<(), Error> {
|
||||
}
|
||||
};
|
||||
|
||||
let pass_items = pass::get_items(&vault)?.items;
|
||||
let mut pass_items = pass::get_items(&vault)?.items;
|
||||
println!("{:?}", pass_items[0]);
|
||||
println!("{}", pass_items.len());
|
||||
|
||||
let rbw_items_partial = rbw::get_items()?;
|
||||
let rbw_items = rbw::get_login_items(rbw_items_partial)?;
|
||||
let mut rbw_items = rbw::get_login_items(rbw_items_partial)?;
|
||||
println!("{:?}", rbw_items[0]);
|
||||
println!("{}", rbw_items.len());
|
||||
|
||||
for rbw_item in rbw_items.clone().iter() {
|
||||
let mut pass_item: Option<&pass::Item> = None;
|
||||
|
||||
'inner: for pass_item_iter in pass_items.iter() {
|
||||
if rbw_item.name == pass_item_iter.content.title {
|
||||
println!("found match! {}", rbw_item.name);
|
||||
pass_item = Some(pass_item_iter);
|
||||
break 'inner;
|
||||
}
|
||||
}
|
||||
|
||||
if let None = pass_item {
|
||||
println!("no match found for {}!", rbw_item.name);
|
||||
continue;
|
||||
}
|
||||
let pass_item = pass_item.unwrap();
|
||||
|
||||
let rbw_password = rbw_item.password.clone();
|
||||
let pass_password = pass_item
|
||||
.clone()
|
||||
.content
|
||||
.content
|
||||
.login
|
||||
.clone()
|
||||
.unwrap()
|
||||
.password;
|
||||
if rbw_password == pass_password {
|
||||
let rbw_index = rbw_items.iter().position(|x| x.id == rbw_item.id).unwrap();
|
||||
rbw_items.remove(rbw_index);
|
||||
|
||||
let pass_index = pass_items.iter().position(|x| x.id == pass_item.id).unwrap();
|
||||
pass_items.remove(pass_index);
|
||||
continue;
|
||||
} else {
|
||||
println!(
|
||||
"password doesn't match! '{}' / '{}'",
|
||||
rbw_password, pass_password
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
println!("remaining {} rbw items", rbw_items.len());
|
||||
println!("remaining {} pass items", pass_items.len());
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
+3
-10
@@ -12,8 +12,6 @@ pub struct Vaults {
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Vault {
|
||||
pub name: String,
|
||||
pub vault_id: String,
|
||||
pub share_id: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
@@ -24,28 +22,23 @@ pub struct Items {
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct Item {
|
||||
pub id: String,
|
||||
pub share_id: String,
|
||||
pub vault_id: String,
|
||||
pub content: ItemContent,
|
||||
pub state: String,
|
||||
pub create_time: String,
|
||||
pub modify_time: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ItemContent {
|
||||
pub title: String,
|
||||
pub note: String,
|
||||
pub item_uuid: String,
|
||||
pub content: ItemContentContent,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ItemContentContent {
|
||||
pub Login: Option<ItemLogin>,
|
||||
#[serde(rename = "Login")]
|
||||
pub login: Option<ItemLogin>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct ItemLogin {
|
||||
pub email: String,
|
||||
pub username: String,
|
||||
|
||||
+11
-5
@@ -14,7 +14,7 @@ pub struct Item {
|
||||
pub type_: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct LoginItem {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
@@ -57,11 +57,14 @@ pub fn get_items() -> Result<Vec<Item>, Error> {
|
||||
}
|
||||
|
||||
pub fn get_login_items(items: Vec<Item>) -> Result<Vec<LoginItem>, Error> {
|
||||
let items = items.iter().filter(|item| item.type_ == "Login").collect::<Vec<&Item>>();
|
||||
let items = items
|
||||
.iter()
|
||||
.filter(|item| item.type_ == "Login")
|
||||
.collect::<Vec<&Item>>();
|
||||
let mut login_items = Vec::<LoginItem>::new();
|
||||
|
||||
for item in items {
|
||||
let password = sh::sh(format!("{} get '{}'", EXECUTABLE, item.name));
|
||||
let password = sh::sh(format!("{} get '{}'", EXECUTABLE, item.id));
|
||||
if let None = item.user {
|
||||
println!("WARNING: user not found for {}", item.name);
|
||||
}
|
||||
@@ -70,9 +73,12 @@ pub fn get_login_items(items: Vec<Item>) -> Result<Vec<LoginItem>, Error> {
|
||||
id: item.id.clone(),
|
||||
name: item.name.clone(),
|
||||
user: item.user.clone(),
|
||||
password: password,
|
||||
password: match password.strip_suffix("\n") {
|
||||
Some(s) => s.to_string(),
|
||||
None => password,
|
||||
},
|
||||
uris: item.uris.clone(),
|
||||
type_: item.type_.clone()
|
||||
type_: item.type_.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user