chore: password refactor #11
16 changed files with 38 additions and 38 deletions
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -28,7 +28,7 @@ use crate::{
|
|||
pub struct Clean {}
|
||||
|
||||
impl RunCommand for Clean {
|
||||
fn run(&self, password_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
fs::write(password_manager.vaults_file, "[]").map_err(LprsError::Io)
|
||||
fn run(&self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
fs::write(vault_manager.vaults_file, "[]").map_err(LprsError::Io)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -47,7 +47,7 @@ pub struct Edit {
|
|||
}
|
||||
|
||||
impl RunCommand for Edit {
|
||||
fn run(&self, mut password_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
fn run(&self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
let index = self.index.get() as usize;
|
||||
|
||||
if let Some(vault) = vault_manager.vaults.get_mut(index - 1) {
|
||||
|
@ -74,7 +74,7 @@ impl RunCommand for Edit {
|
|||
Err(LprsError::InvalidVaultIndex(format!(
|
||||
"The index `{}` is greater than the vaults count {}",
|
||||
self.index,
|
||||
password_manager.vaults.len()
|
||||
vault_manager.vaults.len()
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -34,7 +34,7 @@ pub struct Export {
|
|||
}
|
||||
|
||||
impl RunCommand for Export {
|
||||
fn run(&self, password_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
fn run(&self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if self
|
||||
.path
|
||||
.extension()
|
||||
|
@ -43,10 +43,10 @@ impl RunCommand for Export {
|
|||
if !self.path.exists() {
|
||||
let exported_data = match self.format {
|
||||
Format::Lprs => serde_json::to_string::<Vec<Vault<Encrypted>>>(
|
||||
&password_manager.encrypt_vaults()?,
|
||||
&vault_manager.encrypt_vaults()?,
|
||||
),
|
||||
Format::BitWarden => {
|
||||
serde_json::to_string(&BitWardenPasswords::from(password_manager))
|
||||
serde_json::to_string(&BitWardenPasswords::from(vault_manager))
|
||||
}
|
||||
}?;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -45,7 +45,7 @@ pub struct Gen {
|
|||
}
|
||||
|
||||
impl RunCommand for Gen {
|
||||
fn run(&self, _password_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
fn run(&self, _vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if self.uppercase || self.lowercase || self.numbers || self.symbols {
|
||||
println!(
|
||||
"{}",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -35,7 +35,7 @@ pub struct Import {
|
|||
}
|
||||
|
||||
impl RunCommand for Import {
|
||||
fn run(&self, mut password_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
fn run(&self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if self.path.exists() {
|
||||
if self
|
||||
.path
|
||||
|
@ -46,7 +46,7 @@ impl RunCommand for Import {
|
|||
Format::Lprs => {
|
||||
let vaults = Vaults::try_reload(
|
||||
self.path.to_path_buf(),
|
||||
password_manager.master_password.to_vec(),
|
||||
vault_manager.master_password.to_vec(),
|
||||
)?;
|
||||
let vaults_len = vaults.vaults.len();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -52,8 +52,8 @@ pub struct List {
|
|||
}
|
||||
|
||||
impl RunCommand for List {
|
||||
fn run(&self, password_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if password_manager.vaults.is_empty() {
|
||||
fn run(&self, vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
if vault_manager.vaults.is_empty() {
|
||||
Err(LprsError::Other(
|
||||
"Looks like there is no passwords to list".to_owned(),
|
||||
))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -92,7 +92,7 @@ impl Cli {
|
|||
master_password.into_bytes().into_iter().take(32).collect(),
|
||||
)?
|
||||
};
|
||||
self.command.run(password_manager)?;
|
||||
self.command.run(vault_manager)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -35,17 +35,17 @@ pub struct Remove {
|
|||
}
|
||||
|
||||
impl RunCommand for Remove {
|
||||
fn run(&self, mut password_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
fn run(&self, mut vault_manager: Vaults<Plain>) -> LprsResult<()> {
|
||||
let index = (self.index.get() - 1) as usize;
|
||||
if index > password_manager.vaults.len() {
|
||||
if index > vault_manager.vaults.len() {
|
||||
if !self.force {
|
||||
return Err(LprsError::Other(
|
||||
"The index is greater than the passwords counts".to_owned(),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
password_manager.vaults.remove(index);
|
||||
password_manager.try_export()?;
|
||||
vault_manager.vaults.remove(index);
|
||||
vault_manager.try_export()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -43,8 +43,8 @@
|
|||
/// vault_manager: crate::vault::Vaults,
|
||||
/// ) -> crate::LprsResult<()> {
|
||||
/// match self {
|
||||
/// Self::Test(command) => command.run(password_manager),
|
||||
/// Self::Some(command) => command.run(password_manager),
|
||||
/// Self::Test(command) => command.run(vault_manager),
|
||||
/// Self::Some(command) => command.run(vault_manager),
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
|
@ -63,10 +63,10 @@ macro_rules! create_commands {
|
|||
|
||||
#[automatically_derived]
|
||||
impl $crate::RunCommand for $enum_name{
|
||||
fn run(&self, password_manager: $crate::vault::Vaults<$crate::vault::vault_state::Plain>) -> $crate::LprsResult<()> {
|
||||
fn run(&self, vault_manager: $crate::vault::Vaults<$crate::vault::vault_state::Plain>) -> $crate::LprsResult<()> {
|
||||
match self {
|
||||
$(
|
||||
Self::$varint(command) => command.run(password_manager),
|
||||
Self::$varint(command) => command.run(vault_manager),
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
@ -21,5 +21,5 @@ use crate::{
|
|||
|
||||
/// Trait to run the command
|
||||
pub trait RunCommand {
|
||||
fn run(&self, password_manager: Vaults<Plain>) -> LprsResult<()>;
|
||||
fn run(&self, vault_manager: Vaults<Plain>) -> LprsResult<()>;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Lprs - A local CLI password manager
|
||||
// Lprs - A local CLI vault manager
|
||||
// Copyright (C) 2024 Awiteb <a@4rs.nl>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
|
|
Loading…
Reference in a new issue