pub fn restore(&self, erased: &ErasedPwBox) -> Result<RestoredPwBox, Error> {
        let kdf_factory = self
            .kdfs
            .get(&erased.kdf)
            .ok_or_else(|| Error::NoKdf(erased.kdf.clone()))?;
        let cipher = self
            .ciphers
            .get(&erased.cipher)
            .ok_or_else(|| Error::NoCipher(erased.cipher.clone()))?();
        let kdf = kdf_factory(erased.kdf_params.inner.clone()).map_err(Error::KdfParams)?;

        // Check buffer lengths.
        if erased.kdf_params.salt.len() != kdf.salt_len() {
            return Err(Error::SaltLen);
        }
        if erased.cipher_params.iv.len() != cipher.nonce_len() {
            return Err(Error::NonceLen);
        }
        if erased.encrypted.mac.len() != cipher.mac_len() {
            return Err(Error::MacLen);
        }

        let inner = PwBoxInner {
            salt: erased.kdf_params.salt.clone(),
            nonce: erased.cipher_params.iv.clone(),
            encrypted: erased.encrypted.clone(),
            kdf,
            cipher,
        };
        Ok(RestoredPwBox { inner })
    }
/// Restores a `PwBox` from the serialized form.
Restores a `PwBox` from the serialized form.
Restores a ` PwBox ` from the serialized form .
pub fn restore(&self, erased: &ErasedPwBox) -> Result<RestoredPwBox, Error> {
        let kdf_factory = self
            .kdfs
            .get(&erased.kdf)
            .ok_or_else(|| Error::NoKdf(erased.kdf.clone()))?;
        let cipher = self
            .ciphers
            .get(&erased.cipher)
            .ok_or_else(|| Error::NoCipher(erased.cipher.clone()))?();
        let kdf = kdf_factory(erased.kdf_params.inner.clone()).map_err(Error::KdfParams)?;
        // Check buffer lengths.
        if erased.kdf_params.salt.len() != kdf.salt_len() {
            return Err(Error::SaltLen);
        }
        if erased.cipher_params.iv.len() != cipher.nonce_len() {
            return Err(Error::NonceLen);
        }
        if erased.encrypted.mac.len() != cipher.mac_len() {
            return Err(Error::MacLen);
        }
        let inner = PwBoxInner {
            salt: erased.kdf_params.salt.clone(),
            nonce: erased.cipher_params.iv.clone(),
            encrypted: erased.encrypted.clone(),
            kdf,
            cipher,
        };
        Ok(RestoredPwBox { inner })
    }
pub fn restore ( & self , erased : & ErasedPwBox ) -> Result < RestoredPwBox , Error > { let kdf_factory = self . kdfs . get ( & erased . kdf ) . ok_or_else ( | | Error :: NoKdf ( erased . kdf . clone ( ) ) ) ? ; let cipher = self . ciphers . get ( & erased . cipher ) . ok_or_else ( | | Error :: NoCipher ( erased . cipher . clone ( ) ) ) ? ( ) ; let kdf = kdf_factory ( erased . kdf_params . inner . clone ( ) ) . map_err ( Error :: KdfParams ) ? ; // Check buffer lengths. if erased . kdf_params . salt . len ( ) != kdf . salt_len ( ) { return Err ( Error :: SaltLen ) ; } if erased . cipher_params . iv . len ( ) != cipher . nonce_len ( ) { return Err ( Error :: NonceLen ) ; } if erased . encrypted . mac . len ( ) != cipher . mac_len ( ) { return Err ( Error :: MacLen ) ; } let inner = PwBoxInner { salt : erased . kdf_params . salt . clone ( ) , nonce : erased . cipher_params . iv . clone ( ) , encrypted : erased . encrypted . clone ( ) , kdf , cipher , } ; Ok ( RestoredPwBox { inner } ) }
Restores a `PwBox` from the serialized form.
Restores a ` PwBox ` from the serialized form .
&self
erased
&ErasedPwBox
&self
erased
&ErasedPwBox