Header

Struct Header 

Source
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

Source

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();
Source

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();
Source

pub fn get_size(&self) -> u64

Source

pub fn create_aad(&self) -> Result<Vec<u8>>

This is for creating AAD

It only has support for V3 headers and above

It will return the bytes used for AAD

You may view more about what is used as AAD here.

Source

pub fn write(&self, writer: &mut impl Write) -> Result<()>

This is a convenience function for writing a header to a writer

§Examples
let mut output_file = File::create("test").unwrap();

header.write(&mut output_file).unwrap();

Auto Trait Implementations§

§

impl Freeze for Header

§

impl RefUnwindSafe for Header

§

impl Send for Header

§

impl Sync for Header

§

impl Unpin for Header

§

impl UnwindSafe for Header

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V