bitwarden_core/key_management/
non_generic_wrappers.rs

1//! Structs with generic parameters cannot be moved across FFI bounds (uniffi/wasm).
2//! This module contains wrapper structs that hide the generic parameter with instantiated versions.
3
4use std::ops::Deref;
5
6use serde::{Deserialize, Serialize};
7#[cfg(feature = "wasm")]
8use tsify::Tsify;
9
10use crate::key_management::KeyIds;
11
12/// A non-generic wrapper around `bitwarden-crypto`'s `PasswordProtectedKeyEnvelope`.
13#[derive(Serialize, Deserialize)]
14#[serde(transparent)]
15#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
16pub struct PasswordProtectedKeyEnvelope(
17    #[cfg_attr(
18        feature = "wasm",
19        tsify(type = r#"Tagged<string, "PasswordProtectedKeyEnvelope">"#)
20    )]
21    pub(crate) bitwarden_crypto::safe::PasswordProtectedKeyEnvelope<KeyIds>,
22);
23
24impl Deref for PasswordProtectedKeyEnvelope {
25    type Target = bitwarden_crypto::safe::PasswordProtectedKeyEnvelope<KeyIds>;
26
27    fn deref(&self) -> &Self::Target {
28        &self.0
29    }
30}
31
32impl std::fmt::Debug for PasswordProtectedKeyEnvelope {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        self.0.fmt(f)
35    }
36}