pub struct Header {
pub header_type: HeaderType,
pub nonce: Vec<u8>,
pub salt: Option<[u8; 16]>,
pub keyslots: Option<Vec<Keyslot>>,
}
Expand description
This is the main Header
struct, and it contains all of the information about the encrypted data
It contains the HeaderType
, the nonce, and the salt
This needs to be manually created for encrypting data
Fields§
§header_type: HeaderType
§nonce: Vec<u8>
§salt: Option<[u8; 16]>
§keyslots: Option<Vec<Keyslot>>
Implementations§
Source§impl Header
impl Header
Sourcepub fn deserialize(reader: &mut (impl Read + Seek)) -> Result<(Self, Vec<u8>)>
pub fn deserialize(reader: &mut (impl Read + Seek)) -> Result<(Self, Vec<u8>)>
This is used for deserializing raw bytes from a reader into a Header
struct
This also returns the AAD, read from the header. AAD is only generated in HeaderVersion::V3
and above - it will be blank in older versions.
The AAD needs to be passed to decryption functions in order to validate the header, and decrypt the data.
The AAD for older versions is empty as no AAD is the default for AEADs, and the header validation was not in place prior to V3.
NOTE: This leaves the cursor at 64 bytes into the buffer, as that is the size of the header
§Examples
let header_bytes: [u8; 64] = [
222, 2, 14, 1, 12, 1, 142, 88, 243, 144, 119, 187, 189, 190, 121, 90, 211, 56, 185, 14, 76,
45, 16, 5, 237, 72, 7, 203, 13, 145, 13, 155, 210, 29, 128, 142, 241, 233, 42, 168, 243,
129, 0, 0, 0, 0, 0, 0, 214, 45, 3, 4, 11, 212, 129, 123, 192, 157, 185, 109, 151, 225, 233,
161,
];
let mut cursor = Cursor::new(header_bytes);
// the cursor may be a file, this is just an example
let (header, aad) = Header::deserialize(&mut cursor).unwrap();
Sourcepub fn serialize(&self) -> Result<Vec<u8>>
pub fn serialize(&self) -> Result<Vec<u8>>
This serializes a Header
struct, and returns the raw bytes
The returned bytes may be used as AAD, or written to a file
NOTE: This should NOT be used for validating or creating AAD.
It only has support for V3 headers and above
Create AAD with create_aad()
.
Use the AAD returned from deserialize()
for validation.
§Examples
let header_bytes = header.serialize().unwrap();