|
|
@ -2,7 +2,6 @@ use crate::encoder; |
|
|
|
|
|
|
|
|
|
|
|
use encoder::Encoder; |
|
|
|
use encoder::Encoder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use once_cell::sync::Lazy; |
|
|
|
use once_cell::sync::Lazy; |
|
|
|
|
|
|
|
|
|
|
|
use std::collections::HashSet; |
|
|
|
use std::collections::HashSet; |
|
|
@ -19,7 +18,7 @@ static STORAGE_FOLDER: Lazy<String> = Lazy::new(|| "storage".to_string() ); |
|
|
|
static STORAGE_PATH: Lazy<String> = Lazy::new(|| {
|
|
|
|
static STORAGE_PATH: Lazy<String> = Lazy::new(|| {
|
|
|
|
format!("{}/db.mps", &*STORAGE_FOLDER) |
|
|
|
format!("{}/db.mps", &*STORAGE_FOLDER) |
|
|
|
}); |
|
|
|
}); |
|
|
|
static PASSWORD_TEST_SALT: &str = "MyPasswordStorage1234567890"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)] |
|
|
|
#[derive(Clone)] |
|
|
|
pub struct Item { |
|
|
|
pub struct Item { |
|
|
@ -80,7 +79,7 @@ impl Storage { |
|
|
|
pub fn new(passphrase: String) -> Storage { |
|
|
|
pub fn new(passphrase: String) -> Storage { |
|
|
|
Storage { |
|
|
|
Storage { |
|
|
|
items: HashSet::<Item>::new(), |
|
|
|
items: HashSet::<Item>::new(), |
|
|
|
encoder: Encoder::from(passphrase) |
|
|
|
encoder: Encoder::from(&passphrase) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
pub fn from_db(passphrase: String) -> io::Result<Storage> { |
|
|
|
pub fn from_db(passphrase: String) -> io::Result<Storage> { |
|
|
@ -90,7 +89,7 @@ impl Storage { |
|
|
|
"Storage is not initialized" |
|
|
|
"Storage is not initialized" |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
let encoder = Encoder::from(passphrase); |
|
|
|
let encoder = Encoder::from(&passphrase); |
|
|
|
// TODO: throw error is password is incorrect
|
|
|
|
// TODO: throw error is password is incorrect
|
|
|
|
let file = fs::File::open(&*STORAGE_PATH)?; |
|
|
|
let file = fs::File::open(&*STORAGE_PATH)?; |
|
|
|
let reader = io::BufReader::new(file); |
|
|
|
let reader = io::BufReader::new(file); |
|
|
@ -199,7 +198,7 @@ impl Storage { |
|
|
|
|
|
|
|
|
|
|
|
for item in self.items.iter() { |
|
|
|
for item in self.items.iter() { |
|
|
|
writeln!(file, "{}", item.id)?; |
|
|
|
writeln!(file, "{}", item.id)?; |
|
|
|
let content = self.encoder.encode(item.content.clone()); |
|
|
|
let content = self.encoder.encode(&item.content); |
|
|
|
writeln!(file, "{}", content)?; |
|
|
|
writeln!(file, "{}", content)?; |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|