pub fn deserialize(data: &[u8], password: &[u8]) -> Result<Vec<u8>>
Expand description
Decrypt data with given password
§Error
- if
data
slice is empty (Error::DataIsEmpty) - if
argon2
hasgin function return Error (Error::Argon2Error(Argon2Error)) - if
password
is incorrect (Error::ChaCha20Error(ChaCha20Error))
§Example
use serialize_with_password::{serialize, serialize_no_pass, is_encrypted, deserialize};
let example_data = b"some data";
let encoded = serialize_no_pass(example_data);
let password = b"password";
let encrypted = serialize(example_data, password).unwrap();
assert!(!is_encrypted(&encoded).expect("Data is encrypted correctly"));
assert!(is_encrypted(&encrypted).expect("Data is encrypted correctly"));
assert_eq!(example_data.to_vec(), deserialize(&encoded, b"any string of bytes").expect("Data serialized without password can be deserialized with any password"));
assert_eq!(example_data.to_vec(), deserialize(&encrypted, password).expect("Correct password"));
assert!(deserialize(&encrypted, b"Wrong password").is_err());