Rename the project to lprs

This commit is contained in:
TheAwiteb 2023-12-26 20:53:07 +03:00
parent 6ae8dfb2a3
commit 7b58e9e9a6
No known key found for this signature in database
GPG key ID: ABF818BD15DC2D34
18 changed files with 104 additions and 104 deletions

View file

@ -1,23 +1,23 @@
# Contributing to passrs # Contributing to lprs
Thank you for your interest in contributing to passrs! We welcome contributions from the community to help improve the project. Thank you for your interest in contributing to lprs! We welcome contributions from the community to help improve the project.
## Getting Started ## Getting Started
To get started with contributing to passrs, please follow these steps: To get started with contributing to lprs, please follow these steps:
1. Fork the passrs repository to your own GitHub account. 1. Fork the lprs repository to your own GitHub account.
2. Clone the forked repository to your local machine. 2. Clone the forked repository to your local machine.
3. Create a new branch for your changes: `git checkout -b my-branch-name`. 3. Create a new branch for your changes: `git checkout -b my-branch-name`.
4. Make your desired changes to the codebase. 4. Make your desired changes to the codebase.
5. Test your changes to ensure they work as expected. 5. Test your changes to ensure they work as expected.
6. Commit your changes: `git commit -m "Add my changes"`. 6. Commit your changes: `git commit -m "Add my changes"`.
7. Push your changes to your forked repository: `git push origin my-branch-name`. 7. Push your changes to your forked repository: `git push origin my-branch-name`.
8. Open a pull request from your forked repository to the main passrs repository. 8. Open a pull request from your forked repository to the main lprs repository.
## Code Style ## Code Style
Please follow the existing code style and conventions used in the passrs project. This includes: Please follow the existing code style and conventions used in the lprs project. This includes:
- Using Rust's official formatting tool, `rustfmt`, to format your code. - Using Rust's official formatting tool, `rustfmt`, to format your code.
- Writing clear and concise code with meaningful variable and function names. - Writing clear and concise code with meaningful variable and function names.
@ -25,18 +25,18 @@ Please follow the existing code style and conventions used in the passrs project
## Reporting Issues ## Reporting Issues
If you encounter any issues or bugs while using passrs, please open a new issue on the GitHub repository. When reporting an issue, please provide as much detail as possible, including steps to reproduce the issue and any relevant error messages. If you encounter any issues or bugs while using lprs, please open a new issue on the GitHub repository. When reporting an issue, please provide as much detail as possible, including steps to reproduce the issue and any relevant error messages.
## Feature Requests ## Feature Requests
If you have a feature request or an idea for improving passrs, we encourage you to open a new issue on the GitHub repository. Please describe the feature or improvement in detail and provide any relevant context or examples. If you have a feature request or an idea for improving lprs, we encourage you to open a new issue on the GitHub repository. Please describe the feature or improvement in detail and provide any relevant context or examples.
## Code Review ## Code Review
All contributions to passrs will go through a code review process. This ensures that the code meets the project's standards and maintains its quality. Please be open to feedback and suggestions from the project maintainers during the code review process. All contributions to lprs will go through a code review process. This ensures that the code meets the project's standards and maintains its quality. Please be open to feedback and suggestions from the project maintainers during the code review process.
## License ## License
By contributing to passrs, you agree that your contributions will be licensed under the project's [LICENSE](LICENSE) file. This means that you are granting passrs the right to use, modify, and distribute your contributions under the terms of the license. wich is GPL-3.0 License. By contributing to lprs, you agree that your contributions will be licensed under the project's [LICENSE](LICENSE) file. This means that you are granting lprs the right to use, modify, and distribute your contributions under the terms of the license. wich is GPL-3.0 License.
Happy contributing! Happy contributing!

44
Cargo.lock generated
View file

@ -451,6 +451,28 @@ version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "lprs"
version = "0.1.0"
dependencies = [
"base64",
"clap",
"comfy-table",
"directories",
"log",
"passwords",
"pretty_env_logger",
"regex",
"scanpw",
"serde",
"serde_json",
"serde_with_macros",
"sha256",
"soft-aes",
"thiserror",
"url",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.6.4" version = "2.6.4"
@ -520,28 +542,6 @@ dependencies = [
"windows-targets 0.48.5", "windows-targets 0.48.5",
] ]
[[package]]
name = "passrs"
version = "0.1.0"
dependencies = [
"base64",
"clap",
"comfy-table",
"directories",
"log",
"passwords",
"pretty_env_logger",
"regex",
"scanpw",
"serde",
"serde_json",
"serde_with_macros",
"sha256",
"soft-aes",
"thiserror",
"url",
]
[[package]] [[package]]
name = "passwords" name = "passwords"
version = "3.1.16" version = "3.1.16"

View file

@ -1,12 +1,12 @@
[package] [package]
name = "passrs" name = "lprs"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
license = "GPL-3.0-only" license = "GPL-3.0-only"
authors = ["Awiteb <awiteb@hotmail.com>"] authors = ["Awiteb <awiteb@hotmail.com>"]
readme = "README.md" readme = "README.md"
description = "Local CLI password manager" description = "Local CLI password manager"
repository = "https://github.com/TheAwiteb/passrs" repository = "https://github.com/TheAwiteb/lprs"
rust-version = "1.70.0" rust-version = "1.70.0"
keywords = ["password", "manager", "CLI"] keywords = ["password", "manager", "CLI"]
categories = ["command-line-utilities"] categories = ["command-line-utilities"]

View file

@ -1,34 +1,34 @@
# Passrs # Lprs
Passrs is a local password manager designed to securely store and manage your passwords. Lprs is a local password manager designed to securely store and manage your passwords.
## Installation ## Installation
To install Passrs, you will need to have the Cargo package manager installed. If you do not have Cargo installed, you can install it by following the instructions [here](https://doc.rust-lang.org/cargo/getting-started/installation.html). Note the Minimum Supported Rust Version (MSRV) for Passrs is `1.70.0`. To install Lprs, you will need to have the Cargo package manager installed. If you do not have Cargo installed, you can install it by following the instructions [here](https://doc.rust-lang.org/cargo/getting-started/installation.html). Note the Minimum Supported Rust Version (MSRV) for Lprs is `1.70.0`.
1. Clone the Passrs repository: 1. Clone the Lprs repository:
```bash ```bash
cargo install --locked --git https://github.com/theawiteb/passrs.git cargo install --locked --git https://github.com/theawiteb/lprs.git
``` ```
2. Run Passrs: 2. Run Lprs:
```bash ```bash
passrs --help lprs --help
``` ```
## Uninstallation ## Uninstallation
```bash ```bash
cargo uninstall passrs cargo uninstall lprs
``` ```
## Usage ## Usage
Passrs provides a command-line interface for managing your passwords. The following commands are available: Lprs provides a command-line interface for managing your passwords. The following commands are available:
``` ```
Local CLI password manager Local CLI password manager
Usage: passrs [OPTIONS] <COMMAND> Usage: lprs [OPTIONS] <COMMAND>
Commands: Commands:
add Add new password add Add new password
@ -41,7 +41,7 @@ Commands:
Options: Options:
-p, --passwords-file <PASSWORDS_FILE> -p, --passwords-file <PASSWORDS_FILE>
The passwords json file, default: $HOME/.local/share/passrs/passwords.json The passwords json file, default: $HOME/.local/share/lprs/passwords.json
-h, --help -h, --help
Print help Print help
-V, --version -V, --version
@ -50,13 +50,13 @@ Options:
### Example ### Example
```bash ```bash
passrs add -n "Gmail" -u "some@gmail.com" -p $(passrs gen 19 -u -l -s) -s "https://mail.google.com" lprs add -n "Gmail" -u "some@gmail.com" -p $(lprs gen 19 -u -l -s) -s "https://mail.google.com"
``` ```
#### Result #### Result
This is the result when search for it This is the result when search for it
``` ```
$ passrs list -e "mail" -p -s $ lprs list -e "mail" -p -s
Master Password: *************** Master Password: ***************
+-------+-------+----------------+---------------------+-------------------------+ +-------+-------+----------------+---------------------+-------------------------+
| Index | Name | Username | Password | Service | | Index | Name | Username | Password | Service |
@ -69,13 +69,13 @@ Master Password: ***************
<!-- <!--
### Backup ### Backup
It is important to regularly backup your passwords to prevent data loss. Passrs does not provide an automatic backup feature. To backup your passwords, you can use the export command provided by Passrs. This command allows you to export your encrypted passwords to a json file, which you can then manually backup to a secure location. --> It is important to regularly backup your passwords to prevent data loss. Lprs does not provide an automatic backup feature. To backup your passwords, you can use the export command provided by Lprs. This command allows you to export your encrypted passwords to a json file, which you can then manually backup to a secure location. -->
## Contributing ## Contributing
Contributions to Passrs are welcome! If you would like to contribute, please follow the guidelines outlined in the [CONTRIBUTING](CONTRIBUTING.md) file. Contributions to Lprs are welcome! If you would like to contribute, please follow the guidelines outlined in the [CONTRIBUTING](CONTRIBUTING.md) file.
## License ## License
Passrs is licensed under the GPL-3.0 License. This means that you are free to use, modify, and distribute the software under the terms of this license. Please refer to the [LICENSE](LICENSE) file for more details. Lprs is licensed under the GPL-3.0 License. This means that you are free to use, modify, and distribute the software under the terms of this license. Please refer to the [LICENSE](LICENSE) file for more details.

View file

@ -18,7 +18,7 @@ use clap::Args;
use crate::{ use crate::{
password::{Password, Passwords}, password::{Password, Passwords},
PassrsResult, RunCommand, LprsResult, RunCommand,
}; };
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -29,7 +29,7 @@ pub struct Add {
} }
impl RunCommand for Add { impl RunCommand for Add {
fn run(&self, mut password_manager: Passwords) -> PassrsResult<()> { fn run(&self, mut password_manager: Passwords) -> LprsResult<()> {
password_manager.add_password(self.password_info.clone()); password_manager.add_password(self.password_info.clone());
password_manager.try_export() password_manager.try_export()
} }

View file

@ -18,14 +18,14 @@ use std::fs;
use clap::Args; use clap::Args;
use crate::{password::Passwords, PassrsError, PassrsResult, RunCommand}; use crate::{password::Passwords, LprsError, LprsResult, RunCommand};
#[derive(Debug, Args)] #[derive(Debug, Args)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
pub struct Clean {} pub struct Clean {}
impl RunCommand for Clean { impl RunCommand for Clean {
fn run(&self, password_manager: Passwords) -> PassrsResult<()> { fn run(&self, password_manager: Passwords) -> LprsResult<()> {
fs::write(password_manager.passwords_file, "[]").map_err(PassrsError::Io) fs::write(password_manager.passwords_file, "[]").map_err(LprsError::Io)
} }
} }

View file

@ -20,7 +20,7 @@ use clap::Args;
use crate::{ use crate::{
password::{Password, Passwords}, password::{Password, Passwords},
PassrsError, PassrsResult, RunCommand, LprsError, LprsResult, RunCommand,
}; };
#[derive(Debug, Args)] #[derive(Debug, Args)]
@ -47,7 +47,7 @@ pub struct Edit {
} }
impl RunCommand for Edit { impl RunCommand for Edit {
fn run(&self, mut password_manager: Passwords) -> PassrsResult<()> { fn run(&self, mut password_manager: Passwords) -> LprsResult<()> {
let index = self.index.get() as usize; let index = self.index.get() as usize;
if let Some(password) = password_manager.passwords.get_mut(index - 1) { if let Some(password) = password_manager.passwords.get_mut(index - 1) {
@ -57,7 +57,7 @@ impl RunCommand for Edit {
&& self.service.is_none() && self.service.is_none()
&& self.note.is_none() && self.note.is_none()
{ {
Err(PassrsError::Other( Err(LprsError::Other(
"You must edit one option at least".to_owned(), "You must edit one option at least".to_owned(),
)) ))
} else { } else {
@ -79,7 +79,7 @@ impl RunCommand for Edit {
password_manager.try_export() password_manager.try_export()
} }
} else { } else {
Err(PassrsError::InvalidPasswordIndex(format!( Err(LprsError::InvalidPasswordIndex(format!(
"The index `{}` is greater than the passwords count {}", "The index `{}` is greater than the passwords count {}",
self.index, self.index,
password_manager.passwords.len() password_manager.passwords.len()

View file

@ -18,7 +18,7 @@ use std::num::NonZeroU64;
use clap::Args; use clap::Args;
use crate::{password::Passwords, PassrsError, PassrsResult, RunCommand}; use crate::{password::Passwords, LprsError, LprsResult, RunCommand};
#[derive(Debug, Args)] #[derive(Debug, Args)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -42,7 +42,7 @@ pub struct Gen {
} }
impl RunCommand for Gen { impl RunCommand for Gen {
fn run(&self, _password_manager: Passwords) -> PassrsResult<()> { fn run(&self, _password_manager: Passwords) -> LprsResult<()> {
if self.uppercase || self.lowercase || self.numbers || self.symbols { if self.uppercase || self.lowercase || self.numbers || self.symbols {
println!( println!(
"{}", "{}",
@ -58,7 +58,7 @@ impl RunCommand for Gen {
); );
Ok(()) Ok(())
} else { } else {
Err(PassrsError::Other( Err(LprsError::Other(
"You need to enable at least one kind of characters".to_owned(), "You need to enable at least one kind of characters".to_owned(),
)) ))
} }

View file

@ -20,7 +20,7 @@ use clap::Args;
use comfy_table::Table; use comfy_table::Table;
use regex::Regex; use regex::Regex;
use crate::{password::Passwords, PassrsError, PassrsResult, RunCommand}; use crate::{password::Passwords, LprsError, LprsResult, RunCommand};
#[derive(Debug, Args)] #[derive(Debug, Args)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -49,19 +49,19 @@ pub struct List {
} }
impl RunCommand for List { impl RunCommand for List {
fn run(&self, password_manager: Passwords) -> PassrsResult<()> { fn run(&self, password_manager: Passwords) -> LprsResult<()> {
if password_manager.passwords.is_empty() { if password_manager.passwords.is_empty() {
Err(PassrsError::Other( Err(LprsError::Other(
"Looks like there is no passwords to list".to_owned(), "Looks like there is no passwords to list".to_owned(),
)) ))
} else { } else {
if self.get.is_some() && self.search.is_some() { if self.get.is_some() && self.search.is_some() {
return Err(PassrsError::ArgsConflict( return Err(LprsError::ArgsConflict(
"You cannot use `--get` arg with `--search` arg".to_owned(), "You cannot use `--get` arg with `--search` arg".to_owned(),
)); ));
} }
if self.regex && self.search.is_none() { if self.regex && self.search.is_none() {
return Err(PassrsError::ArgsConflict( return Err(LprsError::ArgsConflict(
"You cannot use `--regex` without `--search` arg".to_owned(), "You cannot use `--regex` without `--search` arg".to_owned(),
)); ));
} }

View file

@ -20,7 +20,7 @@ use clap::Parser;
use crate::{ use crate::{
password::{self, Passwords}, password::{self, Passwords},
PassrsError, PassrsResult, RunCommand, LprsError, LprsResult, RunCommand,
}; };
pub mod add_command; pub mod add_command;
@ -45,7 +45,7 @@ crate::create_commands!(
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
pub struct Cli { pub struct Cli {
/// The passwords json file, default: $HOME/.local/share/passrs/passwords.json /// The passwords json file, default: $HOME/.local/share/lprs/passwords.json
#[arg(short, long)] #[arg(short, long)]
passwords_file: Option<PathBuf>, passwords_file: Option<PathBuf>,
@ -56,7 +56,7 @@ pub struct Cli {
impl Cli { impl Cli {
/// Run the cli /// Run the cli
pub fn run(self) -> PassrsResult<()> { pub fn run(self) -> LprsResult<()> {
let passwords_file = if let Some(ref path) = self.passwords_file { let passwords_file = if let Some(ref path) = self.passwords_file {
path.clone() path.clone()
} else { } else {
@ -77,11 +77,11 @@ impl Cli {
if password::is_new_password_file(&passwords_file)? { if password::is_new_password_file(&passwords_file)? {
let analyzed = passwords::analyzer::analyze(&password); let analyzed = passwords::analyzer::analyze(&password);
if analyzed.length() < 15 { if analyzed.length() < 15 {
return Err(PassrsError::WeakPassword( return Err(LprsError::WeakPassword(
"The password length must be beggier then 15".to_owned(), "The password length must be beggier then 15".to_owned(),
)); ));
} else if passwords::scorer::score(&analyzed) < 80.0 { } else if passwords::scorer::score(&analyzed) < 80.0 {
return Err(PassrsError::WeakPassword( return Err(LprsError::WeakPassword(
"Your password is not stronge enough".to_owned(), "Your password is not stronge enough".to_owned(),
)); ));
} }

View file

@ -18,7 +18,7 @@ use std::num::NonZeroU64;
use clap::Args; use clap::Args;
use crate::{password::Passwords, PassrsError, PassrsResult, RunCommand}; use crate::{password::Passwords, LprsError, LprsResult, RunCommand};
#[derive(Debug, Args)] #[derive(Debug, Args)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@ -32,11 +32,11 @@ pub struct Remove {
} }
impl RunCommand for Remove { impl RunCommand for Remove {
fn run(&self, mut password_manager: Passwords) -> PassrsResult<()> { fn run(&self, mut password_manager: Passwords) -> LprsResult<()> {
let index = (self.index.get() - 1) as usize; let index = (self.index.get() - 1) as usize;
if index > password_manager.passwords.len() { if index > password_manager.passwords.len() {
if !self.force { if !self.force {
return Err(PassrsError::Other( return Err(LprsError::Other(
"The index is greater than the passwords counts".to_owned(), "The index is greater than the passwords counts".to_owned(),
)); ));
} }

View file

@ -29,7 +29,7 @@
/// ``` /// ```
/// #### Output /// #### Output
/// ```rust /// ```rust
/// ///The passrs commands /// ///The lprs commands
/// pub enum TestCommands { /// pub enum TestCommands {
/// ///Test command /// ///Test command
/// Test(TestArgs), /// Test(TestArgs),
@ -41,7 +41,7 @@
/// fn run( /// fn run(
/// &self, /// &self,
/// password_manager: crate::password::Passwords, /// password_manager: crate::password::Passwords,
/// ) -> crate::PassrsResult<()> { /// ) -> crate::LprsResult<()> {
/// match self { /// match self {
/// Self::Test(command) => command.run(password_manager), /// Self::Test(command) => command.run(password_manager),
/// Self::Some(command) => command.run(password_manager), /// Self::Some(command) => command.run(password_manager),
@ -52,7 +52,7 @@
#[macro_export] #[macro_export]
macro_rules! create_commands { macro_rules! create_commands {
(enum $enum_name: ident $($doc:tt, $varint: ident => $command: ty)+) => { (enum $enum_name: ident $($doc:tt, $varint: ident => $command: ty)+) => {
#[doc = "The passrs commands"] #[doc = "The lprs commands"]
#[derive(Debug, clap::Subcommand)] #[derive(Debug, clap::Subcommand)]
pub enum $enum_name { pub enum $enum_name {
$( $(
@ -63,7 +63,7 @@ macro_rules! create_commands {
#[automatically_derived] #[automatically_derived]
impl $crate::RunCommand for $enum_name{ impl $crate::RunCommand for $enum_name{
fn run(&self, password_manager: $crate::password::Passwords) -> $crate::PassrsResult<()> { fn run(&self, password_manager: $crate::password::Passwords) -> $crate::LprsResult<()> {
match self { match self {
$( $(
Self::$varint(command) => command.run(password_manager), Self::$varint(command) => command.run(password_manager),

View file

@ -32,7 +32,7 @@ mod traits;
pub use {macros::*, traits::*}; pub use {macros::*, traits::*};
pub use errors::{Error as PassrsError, Result as PassrsResult}; pub use errors::{Error as LprsError, Result as LprsResult};
pub const STANDARDBASE: GeneralPurpose = GeneralPurpose::new(&alphabet::STANDARD, PAD); pub const STANDARDBASE: GeneralPurpose = GeneralPurpose::new(&alphabet::STANDARD, PAD);

View file

@ -17,19 +17,19 @@
use base64::Engine; use base64::Engine;
use soft_aes::aes::{aes_dec_ecb, aes_enc_ecb}; use soft_aes::aes::{aes_dec_ecb, aes_enc_ecb};
use crate::{PassrsError, PassrsResult}; use crate::{LprsError, LprsResult};
/// Encrypt the string with AEC ECB /// Encrypt the string with AEC ECB
pub fn encrypt(master_password: &[u8], data: &str) -> PassrsResult<String> { pub fn encrypt(master_password: &[u8], data: &str) -> LprsResult<String> {
let padding = Some("PKCS7"); let padding = Some("PKCS7");
aes_enc_ecb(data.as_bytes(), master_password, padding) aes_enc_ecb(data.as_bytes(), master_password, padding)
.map(|d| crate::STANDARDBASE.encode(d)) .map(|d| crate::STANDARDBASE.encode(d))
.map_err(|err| PassrsError::Encryption(err.to_string())) .map_err(|err| LprsError::Encryption(err.to_string()))
} }
/// Decrypt the string with AEC ECB /// Decrypt the string with AEC ECB
pub fn decrypt(master_password: &[u8], data: &str) -> PassrsResult<String> { pub fn decrypt(master_password: &[u8], data: &str) -> LprsResult<String> {
let padding = Some("PKCS7"); let padding = Some("PKCS7");
aes_dec_ecb( aes_dec_ecb(
@ -39,10 +39,10 @@ pub fn decrypt(master_password: &[u8], data: &str) -> PassrsResult<String> {
) )
.map_err(|err| { .map_err(|err| {
if err.to_string().contains("Invalid padding") { if err.to_string().contains("Invalid padding") {
PassrsError::WrongMasterPassword LprsError::WrongMasterPassword
} else { } else {
PassrsError::Decryption(err.to_string()) LprsError::Decryption(err.to_string())
} }
}) })
.map(|d| String::from_utf8(d).map_err(PassrsError::Utf8))? .map(|d| String::from_utf8(d).map_err(LprsError::Utf8))?
} }

View file

@ -19,7 +19,7 @@ use std::{fs, path::PathBuf};
use clap::Parser; use clap::Parser;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{PassrsError, PassrsResult}; use crate::{LprsError, LprsResult};
pub mod cipher; pub mod cipher;
mod validator; mod validator;
@ -62,7 +62,7 @@ pub struct Password {
impl Password { impl Password {
/// Encrypt the password data /// Encrypt the password data
pub fn encrypt(self, master_password: &[u8]) -> PassrsResult<Self> { pub fn encrypt(self, master_password: &[u8]) -> LprsResult<Self> {
Ok(Self { Ok(Self {
name: cipher::encrypt(master_password, &self.name)?, name: cipher::encrypt(master_password, &self.name)?,
username: cipher::encrypt(master_password, &self.username)?, username: cipher::encrypt(master_password, &self.username)?,
@ -79,7 +79,7 @@ impl Password {
} }
/// Decrypt the password data /// Decrypt the password data
pub fn decrypt(self, master_password: &[u8]) -> PassrsResult<Self> { pub fn decrypt(self, master_password: &[u8]) -> LprsResult<Self> {
Ok(Self { Ok(Self {
name: cipher::decrypt(master_password, &self.name)?, name: cipher::decrypt(master_password, &self.name)?,
username: cipher::decrypt(master_password, &self.username)?, username: cipher::decrypt(master_password, &self.username)?,
@ -111,32 +111,32 @@ impl Passwords {
} }
/// Encrypt the passwords /// Encrypt the passwords
fn encrypt(self) -> PassrsResult<Self> { fn encrypt(self) -> LprsResult<Self> {
Ok(Self { Ok(Self {
passwords: self passwords: self
.passwords .passwords
.into_iter() .into_iter()
.map(|p| p.encrypt(&self.master_password)) .map(|p| p.encrypt(&self.master_password))
.collect::<PassrsResult<Vec<Password>>>()?, .collect::<LprsResult<Vec<Password>>>()?,
..self ..self
}) })
} }
/// Reload the passwords from the file /// Reload the passwords from the file
pub fn try_reload(passwords_file: PathBuf, master_password: Vec<u8>) -> PassrsResult<Self> { pub fn try_reload(passwords_file: PathBuf, master_password: Vec<u8>) -> LprsResult<Self> {
let passwords = let passwords =
serde_json::from_str::<Vec<Password>>(&fs::read_to_string(&passwords_file)?)? serde_json::from_str::<Vec<Password>>(&fs::read_to_string(&passwords_file)?)?
.into_iter() .into_iter()
.map(|p| p.decrypt(master_password.as_slice())) .map(|p| p.decrypt(master_password.as_slice()))
.collect::<PassrsResult<Vec<Password>>>()?; .collect::<LprsResult<Vec<Password>>>()?;
Ok(Self::new(master_password, passwords_file, passwords)) Ok(Self::new(master_password, passwords_file, passwords))
} }
/// Export the passwords to the file /// Export the passwords to the file
pub fn try_export(self) -> PassrsResult<()> { pub fn try_export(self) -> LprsResult<()> {
let path = self.passwords_file.to_path_buf(); let path = self.passwords_file.to_path_buf();
fs::write(path, serde_json::to_string(&self.encrypt()?.passwords)?).map_err(PassrsError::Io) fs::write(path, serde_json::to_string(&self.encrypt()?.passwords)?).map_err(LprsError::Io)
} }
/// Add new password /// Add new password

View file

@ -16,12 +16,12 @@
use std::{fs, path::Path}; use std::{fs, path::Path};
use crate::PassrsResult; use crate::LprsResult;
use super::Password; use super::Password;
/// Return if the password file new file or not /// Return if the password file new file or not
pub fn is_new_password_file(path: &Path) -> PassrsResult<bool> { pub fn is_new_password_file(path: &Path) -> LprsResult<bool> {
if path.exists() { if path.exists() {
let file_content = fs::read_to_string(path)?; let file_content = fs::read_to_string(path)?;
if !file_content.is_empty() if !file_content.is_empty()

View file

@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>. // along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
use crate::{password::Passwords, PassrsResult}; use crate::{password::Passwords, LprsResult};
/// Trait to run the command /// Trait to run the command
pub trait RunCommand { pub trait RunCommand {
fn run(&self, password_manager: Passwords) -> PassrsResult<()>; fn run(&self, password_manager: Passwords) -> LprsResult<()>;
} }

View file

@ -16,11 +16,11 @@
use std::{fs, path::PathBuf}; use std::{fs, path::PathBuf};
use crate::{PassrsError, PassrsResult}; use crate::{LprsError, LprsResult};
/// Return the default passwords json file /// Return the default passwords json file
pub fn passwords_file() -> PassrsResult<PathBuf> { pub fn passwords_file() -> LprsResult<PathBuf> {
if let Some(path) = directories::ProjectDirs::from("", "", "passrs") if let Some(path) = directories::ProjectDirs::from("", "", "lprs")
.map(|d| d.data_local_dir().to_path_buf().join("passwords.json")) .map(|d| d.data_local_dir().to_path_buf().join("passwords.json"))
{ {
if let Some(parent) = path.parent() { if let Some(parent) = path.parent() {
@ -31,7 +31,7 @@ pub fn passwords_file() -> PassrsResult<PathBuf> {
} }
Ok(path) Ok(path)
} else { } else {
Err(PassrsError::ProjectDir( Err(LprsError::ProjectDir(
"Can't extract the project_dir from this OS".to_owned(), "Can't extract the project_dir from this OS".to_owned(),
)) ))
} }