pub fn decrypt_with_password(&mut self, passphrase: &str) -> Result<(), Error> {
        let mut encrypted_key = self.complete_key.clone(); // Cheap :)

        match Self::inner_kdf_mix(
            &mut encrypted_key[..32],
            self.kdf_rounds,
            &self.salt,
            passphrase,
        ) {
            Ok(_) => {
                // Since the decryption worked, its now "unencrypted", even if the passphrase was wrong
                // and the value is garbage.
                let decrypted_key = UnencryptedKey(encrypted_key);
                let current_checksum = Self::calculate_checksum(&decrypted_key);

                // Non-constant time is fine since checksum is public.
                if current_checksum != self.checksum {
                    return Err(Error::BadPassword);
                }

                // Confirmed the decryption worked, mutating the key structure.
                self.complete_key = decrypted_key.0;
                Ok(())
            }
            Err(e) => Err(e),
        }
    }
/// Decrypts a secret key that was stored in encrypted form with the passphrase.
///
/// # Errors
///
/// This returns an error if the provided password was empty or if it failed to decrypt the key.
Decrypts a secret key that was stored in encrypted form with the passphrase.
Decrypts a secret key that was stored in encrypted form with the passphrase .
pub fn decrypt_with_password(&mut self, passphrase: &str) -> Result<(), Error> {
        let mut encrypted_key = self.complete_key.clone(); // Cheap :)
        match Self::inner_kdf_mix(
            &mut encrypted_key[..32],
            self.kdf_rounds,
            &self.salt,
            passphrase,
        ) {
            Ok(_) => {
                // Since the decryption worked, its now "unencrypted", even if the passphrase was wrong
                // and the value is garbage.
                let decrypted_key = UnencryptedKey(encrypted_key);
                let current_checksum = Self::calculate_checksum(&decrypted_key);
                // Non-constant time is fine since checksum is public.
                if current_checksum != self.checksum {
                    return Err(Error::BadPassword);
                }
                // Confirmed the decryption worked, mutating the key structure.
                self.complete_key = decrypted_key.0;
                Ok(())
            }
            Err(e) => Err(e),
        }
    }
pub fn decrypt_with_password ( & mut self , passphrase : & str ) -> Result < ( ) , Error > { let mut encrypted_key = self . complete_key . clone ( ) ; // Cheap :) match Self :: inner_kdf_mix ( & mut encrypted_key [ .. 32 ] , self . kdf_rounds , & self . salt , passphrase , ) { Ok ( _ ) => { // Since the decryption worked, its now "unencrypted", even if the passphrase was wrong // and the value is garbage. let decrypted_key = UnencryptedKey ( encrypted_key ) ; let current_checksum = Self :: calculate_checksum ( & decrypted_key ) ; // Non-constant time is fine since checksum is public. if current_checksum != self . checksum { return Err ( Error :: BadPassword ) ; } // Confirmed the decryption worked, mutating the key structure. self . complete_key = decrypted_key . 0 ; Ok ( ( ) ) } Err ( e ) => Err ( e ) , } }
Decrypts a secret key that was stored in encrypted form with the passphrase.
Decrypts a secret key that was stored in encrypted form with the passphrase .
&mut self
passphrase
&str
&mut self
passphrase
&str
errors
This returns an error if the provided password was empty or if it failed to decrypt the key.
This returns an error if the provided password was empty or if it failed to decrypt the key .