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