[][src]Struct pwbox::Eraser

pub struct Eraser { /* fields omitted */ }

Helper structure to convert password-encrypted boxes to a serializable format and back.

Examples

let mut eraser = Eraser::new();
// Register separate KDFs and ciphers
eraser.add_kdf::<SomeKdf>("some-kdf");
eraser.add_cipher::<SomeCipher>("some-cipher");
// Add a suite.
eraser.add_suite::<SomeSuite>();

// Erase a `PwBox`.
let pwbox = SomeSuite::build_box(&mut thread_rng())
    .seal("password", b"some data")
    .unwrap();
let erased = eraser.erase(&pwbox).unwrap();
// `erased` can now be serialized somewhere, e.g., in JSON format.

// Restore a `PwBox`.
let restored = eraser.restore(&erased).unwrap();
assert_eq!(&*restored.open("password").unwrap(), b"some data");

Implementations

impl Eraser[src]

pub fn new() -> Self[src]

Creates an Eraser with no ciphers or KDFs.

pub fn add_cipher<C>(&mut self, cipher_name: &str) -> &mut Self where
    C: Cipher
[src]

Adds a cipher.

Panics

Panics if the cipher is already registered under a different name, or if cipher_name is already registered.

pub fn add_kdf<K>(&mut self, kdf_name: &str) -> &mut Self where
    K: DeriveKey + DeserializeOwned + Default
[src]

Adds a key derivation function.

Panics

Panics if the KDF is already registered under a different name, or if kdf_name is already registered.

pub fn add_suite<S: Suite>(&mut self) -> &mut Self[src]

Adds all KDFs and ciphers from the specified Suite.

Panics

This method panics if any KDF or cipher in the suite (or its name) have been registered previously. A panic is also raised if the suite has not registered its recommended cipher or KDF.

pub fn erase<K, C>(
    &self,
    pwbox: &PwBox<K, C>
) -> Result<ErasedPwBox, EraseError> where
    K: DeriveKey + Serialize,
    C: Cipher
[src]

Converts a pwbox into serializable form.

pub fn restore(&self, erased: &ErasedPwBox) -> Result<RestoredPwBox, Error>[src]

Restores a PwBox from the serialized form.

Trait Implementations

impl Debug for Eraser[src]

impl Default for Eraser[src]

Auto Trait Implementations

impl !RefUnwindSafe for Eraser

impl !Send for Eraser

impl !Sync for Eraser

impl Unpin for Eraser

impl !UnwindSafe for Eraser

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.