bitwarden_vault/cipher_risk/
types.rs1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4#[cfg(feature = "wasm")]
5use {tsify::Tsify, wasm_bindgen::prelude::*};
6
7use crate::CipherId;
8
9#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
11#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
12#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
13#[serde(tag = "type", content = "value")]
14pub enum ExposedPasswordResult {
15 NotChecked,
17 Found(u32),
19 Error(String),
21}
22
23#[derive(Serialize, Deserialize, Debug, Clone)]
25#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
26#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
27pub struct CipherLoginDetails {
28 pub id: CipherId,
30 pub password: String,
32 pub username: Option<String>,
34}
35
36#[derive(Serialize, Deserialize, Debug, Clone)]
38#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
39#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
40#[serde(transparent)]
41pub struct PasswordReuseMap {
42 #[cfg_attr(feature = "wasm", tsify(type = "Record<string, number>"))]
44 pub map: HashMap<String, u32>,
45}
46
47impl PasswordReuseMap {
48 pub fn new(passwords: Vec<CipherLoginDetails>) -> Self {
50 let mut map = HashMap::new();
51 for details in passwords {
52 if !details.password.is_empty() {
53 *map.entry(details.password).or_insert(0) += 1;
54 }
55 }
56 Self { map }
57 }
58}
59
60#[derive(Serialize, Deserialize, Debug, Clone, Default)]
62#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
63#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
64#[serde(rename_all = "camelCase")]
65pub struct CipherRiskOptions {
66 #[serde(default)]
69 pub password_map: Option<PasswordReuseMap>,
70 #[serde(default)]
73 pub check_exposed: bool,
74 #[serde(default)]
77 pub hibp_base_url: Option<String>,
78}
79
80#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
82#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
83#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
84pub struct CipherRiskResult {
85 pub id: CipherId,
87 pub password_strength: u8,
90 pub exposed_result: ExposedPasswordResult,
95 pub reuse_count: Option<u32>,
98}