}\r
\r
/// Encrypt the given text with the given key. The key length must be 128 bits encoded in base64.\r
-/// Ouput format:\r
-/// Format "1" + base_64(<IV> + <hash(message)> + <aes(message)>)\r
+/// Ouput format: "1" + base_64(<IV> + <hash(message)> + <aes(message)>)\r
/// IV: 16 bytes randomized.\r
/// Mode : CBC.\r
pub fn encrypt(key: &str, plain_text: &str) -> Result<String, EncryptError> {\r
let iv = rand::thread_rng().gen::<[u8; 16]>();\r
\r
let cipher_text =\r
- match symm::encrypt(symm::Cipher::aes_128_cbc(), &key_as_bytes, Some(&iv), text_as_bytes) {\r
- Ok(t) => t,\r
- Err(_e) => return Err(EncryptError::UnableToEncrypt)\r
- };\r
+ symm::encrypt(symm::Cipher::aes_128_cbc(), &key_as_bytes, Some(&iv), text_as_bytes)\r
+ .map_err(|_e| EncryptError::UnableToEncrypt)?;\r
\r
let hash_text = sha256(&text_as_bytes);\r
\r
Ok(String::from("1") + &base64::encode(&result))\r
}\r
\r
-/// TODO: return a Result<string, DecryptError>\r
+/// Decrypt the given text with the given key. The key length must be 128 bits encoded in base64.\r
+/// Input format: "1" + base_64(<IV> + <hash(message)> + <aes(message)>)\r
pub fn decrypt(key: &str, cipher_text: &str) -> Result<String, DecryptError> {\r
let key_as_bytes = decode_key(key).map_err(|e| DecryptError::KeyError(e))?;\r
\r