use bitwarden_crypto::{
EncString, KeyStore, SymmetricCryptoKey, key_slot_ids, safe::PasswordProtectedKeyEnvelope,
};
#[cfg(feature = "internal")]
pub mod account_cryptographic_state;
#[cfg(feature = "internal")]
pub mod crypto;
#[cfg(feature = "internal")]
mod crypto_client;
use bitwarden_encoding::B64;
#[cfg(feature = "internal")]
pub use crypto_client::CryptoClient;
#[cfg(feature = "internal")]
mod master_password;
#[cfg(feature = "internal")]
pub use master_password::{
MasterPasswordAuthenticationData, MasterPasswordError, MasterPasswordUnlockData,
};
#[cfg(feature = "internal")]
mod security_state;
#[cfg(feature = "internal")]
pub use security_state::{
BLOB_SECURITY_VERSION, MINIMUM_ENFORCE_ICON_URI_HASH_VERSION, SecurityState,
SignedSecurityState,
};
#[cfg(feature = "internal")]
mod user_decryption;
use serde::{Deserialize, Serialize};
#[cfg(feature = "wasm")]
use tsify::Tsify;
#[cfg(feature = "internal")]
pub use user_decryption::UserDecryptionData;
#[cfg(feature = "internal")]
mod v2_upgrade_token;
#[cfg(feature = "internal")]
pub use v2_upgrade_token::{V2UpgradeToken, V2UpgradeTokenError};
#[cfg(all(feature = "internal", feature = "wasm"))]
mod wasm_unlock_state;
#[cfg(feature = "internal")]
mod local_user_data_key;
#[cfg(feature = "internal")]
mod local_user_data_key_state;
#[cfg(feature = "internal")]
pub mod state_bridge;
use crate::{OrganizationId, UserId};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[repr(transparent)]
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct UserKeyState {
decrypted_user_key: B64,
}
bitwarden_state::register_repository_item!(String => UserKeyState, "UserKey");
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct LocalUserDataKeyState {
wrapped_key: EncString,
}
bitwarden_state::register_repository_item!(UserId => LocalUserDataKeyState, "LocalUserDataKey");
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct EphemeralPinEnvelopeState {
pin_envelope: PasswordProtectedKeyEnvelope,
}
bitwarden_state::register_repository_item!(String => EphemeralPinEnvelopeState, "EphemeralPinEnvelope");
key_slot_ids! {
#[symmetric]
pub enum SymmetricKeySlotId {
Master,
User,
Organization(OrganizationId),
LocalUserData,
#[local]
Local(LocalId),
}
#[private]
pub enum PrivateKeySlotId {
UserPrivateKey,
#[local]
Local(LocalId),
}
#[signing]
pub enum SigningKeySlotId {
UserSigningKey,
#[local]
Local(LocalId),
}
pub KeySlotIds => SymmetricKeySlotId, PrivateKeySlotId, SigningKeySlotId;
}
pub fn create_test_crypto_with_user_key(key: SymmetricCryptoKey) -> KeyStore<KeySlotIds> {
let store = KeyStore::default();
#[allow(deprecated)]
store
.context_mut()
.set_symmetric_key(SymmetricKeySlotId::User, key.clone())
.expect("Mutable context");
store
}
pub fn create_test_crypto_with_user_and_org_key(
key: SymmetricCryptoKey,
org_id: OrganizationId,
org_key: SymmetricCryptoKey,
) -> KeyStore<KeySlotIds> {
let store = KeyStore::default();
#[allow(deprecated)]
store
.context_mut()
.set_symmetric_key(SymmetricKeySlotId::User, key.clone())
.expect("Mutable context");
#[allow(deprecated)]
store
.context_mut()
.set_symmetric_key(SymmetricKeySlotId::Organization(org_id), org_key.clone())
.expect("Mutable context");
store
}