|
|
|
@ -31,8 +31,7 @@ impl Encoder {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: error type
|
|
|
|
|
// TODO: rename to encrypt
|
|
|
|
|
pub fn encode(&self, plain_text: &String) -> String { |
|
|
|
|
pub fn encrypt(&self, plain_text: &String) -> String { |
|
|
|
|
let key = Key::<Aes256Gcm>::from_slice(self.passphrase.as_bytes());
|
|
|
|
|
let nonce = Aes256Gcm::generate_nonce(&mut OsRng); |
|
|
|
|
|
|
|
|
@ -52,8 +51,7 @@ impl Encoder {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: review error type
|
|
|
|
|
// TODO: rename to decrypt
|
|
|
|
|
pub fn decode(&self, encrypted_data: String) -> io::Result<String> { |
|
|
|
|
pub fn decrypt(&self, encrypted_data: String) -> io::Result<String> { |
|
|
|
|
let encrypted_data = hex::decode(encrypted_data) |
|
|
|
|
.expect("failed to decode hex string into vec"); |
|
|
|
|
|
|
|
|
@ -78,16 +76,13 @@ impl Encoder {
|
|
|
|
|
Ok(result) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn test_encoded_passphrase(&self, piassphrase_encoded: String) -> bool { |
|
|
|
|
// TODO: implement
|
|
|
|
|
//self.passphrase == passphrase_encoded
|
|
|
|
|
// Encoder::get_encoded_test_passphrase();
|
|
|
|
|
return true; |
|
|
|
|
pub fn test_encoded_passphrase(&self, passphrase_encrypted: String) -> io::Result<bool> { |
|
|
|
|
let decrypted = self.decrypt(passphrase_encrypted)?; |
|
|
|
|
Ok(PASSWORD_TEST == decrypted) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn get_encoded_test_passphrase(&self) -> String { |
|
|
|
|
// TODO: use this
|
|
|
|
|
self.passphrase.clone() |
|
|
|
|
self.encrypt(&PASSWORD_TEST.to_string()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|