nethsm_backup

Struct BackupDecryptor

source
pub struct BackupDecryptor<'a> {
    pub(crate) backup: &'a Backup,
    pub(crate) cipher: Aes256Gcm,
}
Expand description

Backup decryptor which decrypts backup items on the fly.

Fields§

§backup: &'a Backup§cipher: Aes256Gcm

Implementations§

source§

impl<'a> BackupDecryptor<'a>

source

pub(crate) fn new(backup: &'a Backup, passphrase: &[u8]) -> Result<Self>

Create a new BackupDecryptor using a Backup and a passphrase.

§Errors

Even though this function returns a Result it is unlikely to fail since all parameters are static.

source

pub(crate) fn decrypt(&self, ciphertext: &[u8], aad: &[u8]) -> Result<Vec<u8>>

Decrypts ciphertext while verifying additional data (aad).

§Errors

Returns:

  • Error::Decryption if a decryption error is encountered, for example the ciphertext is of incorrect length, has been tampered with, the decryption passphrase is wrong or the additional authenticated data is incorrect.
source

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

Decrypted backup version.

§Errors

Returns:

  • Error::Decryption if a decryption error is encountered, for example the encrypted version is of incorrect length, has been tampered with, the decryption passphrase is wrong or the additional authenticated data is incorrect (e.g. a different encrypted piece of data is impersonating the backup version).
source

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

Decrypted domain key.

§Errors

Returns:

  • Error::Decryption if a decryption error is encountered, for example the encrypted domain key is of incorrect length, has been tampered with, the decryption passphrase is wrong or the additional authenticated data is incorrect (e.g. a different encrypted piece of data is impersonating the domain key).
source

pub fn items_iter( &'a self, ) -> impl Iterator<Item = Result<(String, Vec<u8>)>> + 'a

Returns an iterator over backup entries.

The entries are pairs of keys (which are strings) and values (byte vectors). Since the entries are decrypted as they are being read the pairs are wrapped in Results.

§Errors

This function does not fail but reading the inner iterator may return errors:

  • Error::Decryption if a decryption error is encountered, for example the encrypted entry is of incorrect length, has been tampered with, the decryption passphrase is wrong or the additional authenticated data is incorrect (e.g. a different encrypted piece of data is impersonating the backup entry).
  • Error::Utf8 if the entry’s key is not a well-formed UTF-8 string.

Auto Trait Implementations§

§

impl<'a> Freeze for BackupDecryptor<'a>

§

impl<'a> RefUnwindSafe for BackupDecryptor<'a>

§

impl<'a> Send for BackupDecryptor<'a>

§

impl<'a> Sync for BackupDecryptor<'a>

§

impl<'a> Unpin for BackupDecryptor<'a>

§

impl<'a> UnwindSafe for BackupDecryptor<'a>

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.