|
|
|
@ -76,7 +76,7 @@ impl Encoder {
|
|
|
|
|
pub fn from(passphrase: String) -> Encoder { |
|
|
|
|
Encoder { passphrase } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: get by ref
|
|
|
|
|
pub fn encode(&self, line: String) -> String { |
|
|
|
|
// TODO: use passphrasee to encode
|
|
|
|
@ -91,10 +91,16 @@ impl Encoder {
|
|
|
|
|
Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn test_encoded_passphrase(&self, test_passphrase_encoded: String) -> bool { |
|
|
|
|
self.passphrase == test_passphrase_encoded |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn get_encoded_test_passphrase(&self) -> String { |
|
|
|
|
// TODO: encode SALT const with passphrase
|
|
|
|
|
self.passphrase.clone() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub struct Storage { |
|
|
|
@ -131,6 +137,9 @@ impl Storage {
|
|
|
|
|
"Bad storage db format: no passphrase in the beginnning" |
|
|
|
|
)), |
|
|
|
|
}; |
|
|
|
|
if !encoder.test_encoded_passphrase(passtest) { |
|
|
|
|
return Err(io::Error::new(io::ErrorKind::InvalidData, "Wrong passphrase")); |
|
|
|
|
} |
|
|
|
|
for line in lines { |
|
|
|
|
match line { |
|
|
|
|
Ok(line) => { |
|
|
|
@ -148,8 +157,8 @@ impl Storage {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Ok(Storage { |
|
|
|
|
items: items, |
|
|
|
|
encoder: encoder |
|
|
|
|
items, |
|
|
|
|
encoder |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|