pub fn validate_header(data: &[u8], data_type: DataType) -> boolExpand description
Only validate the header to make sure it is valid. Used to quickly determine if the data comes from the library.
§Arguments
data- The data to verify.data_type- The type of the data.
§Returns
true if the header is valid, false if it is not.
§Example
use devolutions_crypto::DataType;
use devolutions_crypto::ciphertext::{encrypt, CiphertextVersion};
use devolutions_crypto::utils::{generate_key, validate_header};
let key = generate_key(32).expect("generate key shouldn't fail");
let ciphertext: Vec<u8> = encrypt(b"test", &key, CiphertextVersion::Latest)
.expect("encryption shouldn't fail")
.into();
assert!(validate_header(&ciphertext, DataType::Ciphertext));
assert!(!validate_header(&ciphertext, DataType::PasswordHash));
assert!(!validate_header(&key, DataType::Ciphertext));