bitwarden_vault/mobile/
password_history_client.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use bitwarden_core::{Client, Error};
use bitwarden_crypto::{KeyDecryptable, KeyEncryptable};

use crate::{PasswordHistory, PasswordHistoryView, VaultClient};

pub struct ClientPasswordHistory<'a> {
    pub(crate) client: &'a Client,
}

impl ClientPasswordHistory<'_> {
    pub fn encrypt(&self, history_view: PasswordHistoryView) -> Result<PasswordHistory, Error> {
        let enc = self.client.internal.get_encryption_settings()?;
        let key = enc.get_key(&None)?;

        let history = history_view.encrypt_with_key(key)?;

        Ok(history)
    }

    pub fn decrypt_list(
        &self,
        history: Vec<PasswordHistory>,
    ) -> Result<Vec<PasswordHistoryView>, Error> {
        let enc = self.client.internal.get_encryption_settings()?;
        let key = enc.get_key(&None)?;

        let history_view = history.decrypt_with_key(key)?;

        Ok(history_view)
    }
}

impl<'a> VaultClient<'a> {
    pub fn password_history(&'a self) -> ClientPasswordHistory<'a> {
        ClientPasswordHistory {
            client: self.client,
        }
    }
}