bitwarden_vault/
client_totp.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
use chrono::{DateTime, Utc};

use crate::{
    generate_totp, generate_totp_cipher_view, CipherListView, ClientVault, TotpError, TotpResponse,
};

impl<'a> ClientVault<'a> {
    /// Generate a TOTP code from a provided key.
    ///
    /// Key can be either:
    /// - A base32 encoded string
    /// - OTP Auth URI
    /// - Steam URI
    pub fn generate_totp(
        &'a self,
        key: String,
        time: Option<DateTime<Utc>>,
    ) -> Result<TotpResponse, TotpError> {
        generate_totp(key, time)
    }

    /// Generate a TOTP code from a provided cipher list view.
    pub fn generate_totp_cipher_view(
        &'a self,
        view: CipherListView,
        time: Option<DateTime<Utc>>,
    ) -> Result<TotpResponse, TotpError> {
        let enc = self.client.internal.get_encryption_settings()?;

        generate_totp_cipher_view(&enc, view, time)
    }
}