pub fn from_pickle(
        pickle: PickledRecoveryKey,
        pickle_key: &[u8],
    ) -> Result<Self, UnpicklingError> {
        let pickled: InnerPickle = serde_json::from_str(pickle.as_ref())?;

        let key = GenericArray::from_slice(pickle_key);
        let cipher = Aes256Gcm::new(key);

        let nonce = decode_url_safe(pickled.nonce).map_err(DecodeError::from)?;
        let nonce = GenericArray::from_slice(&nonce);
        let ciphertext = &decode_url_safe(pickled.ciphertext).map_err(DecodeError::from)?;

        let decrypted = cipher
            .decrypt(nonce, ciphertext.as_slice())
            .map_err(|e| UnpicklingError::Decryption(e.to_string()))?;

        if decrypted.len() != Self::KEY_SIZE {
            Err(DecodeError::Length(decrypted.len(), Self::KEY_SIZE).into())
        } else {
            let mut key = [0u8; Self::KEY_SIZE];
            key.copy_from_slice(&decrypted);

            Ok(Self { inner: key })
        }
    }
/// Try to import a `RecoveryKey` from a previously exported pickle.
Try to import a `RecoveryKey` from a previously exported pickle.
Try to import a ` RecoveryKey ` from a previously exported pickle .
pub fn from_pickle(
        pickle: PickledRecoveryKey,
        pickle_key: &[u8],
    ) -> Result<Self, UnpicklingError> {
        let pickled: InnerPickle = serde_json::from_str(pickle.as_ref())?;
        let key = GenericArray::from_slice(pickle_key);
        let cipher = Aes256Gcm::new(key);
        let nonce = decode_url_safe(pickled.nonce).map_err(DecodeError::from)?;
        let nonce = GenericArray::from_slice(&nonce);
        let ciphertext = &decode_url_safe(pickled.ciphertext).map_err(DecodeError::from)?;
        let decrypted = cipher
            .decrypt(nonce, ciphertext.as_slice())
            .map_err(|e| UnpicklingError::Decryption(e.to_string()))?;
        if decrypted.len() != Self::KEY_SIZE {
            Err(DecodeError::Length(decrypted.len(), Self::KEY_SIZE).into())
        } else {
            let mut key = [0u8; Self::KEY_SIZE];
            key.copy_from_slice(&decrypted);
            Ok(Self { inner: key })
        }
    }
pub fn from_pickle ( pickle : PickledRecoveryKey , pickle_key : & [ u8 ] , ) -> Result < Self , UnpicklingError > { let pickled : InnerPickle = serde_json :: from_str ( pickle . as_ref ( ) ) ? ; let key = GenericArray :: from_slice ( pickle_key ) ; let cipher = Aes256Gcm :: new ( key ) ; let nonce = decode_url_safe ( pickled . nonce ) . map_err ( DecodeError :: from ) ? ; let nonce = GenericArray :: from_slice ( & nonce ) ; let ciphertext = & decode_url_safe ( pickled . ciphertext ) . map_err ( DecodeError :: from ) ? ; let decrypted = cipher . decrypt ( nonce , ciphertext . as_slice ( ) ) . map_err ( | e | UnpicklingError :: Decryption ( e . to_string ( ) ) ) ? ; if decrypted . len ( ) != Self :: KEY_SIZE { Err ( DecodeError :: Length ( decrypted . len ( ) , Self :: KEY_SIZE ) . into ( ) ) } else { let mut key = [ 0u8 ; Self :: KEY_SIZE ] ; key . copy_from_slice ( & decrypted ) ; Ok ( Self { inner : key } ) } }
Try to import a `RecoveryKey` from a previously exported pickle.
Try to import a ` RecoveryKey ` from a previously exported pickle .
pickle
PickledRecoveryKey
pickle_key
&[u8]
pickle
PickledRecoveryKey
pickle_key
&[u8]