bitwarden_uniffi/
crypto.rs1use bitwarden_core::key_management::crypto::{
2 DeriveKeyConnectorRequest, DerivePinKeyResponse, EnrollPinResponse, InitOrgCryptoRequest,
3 InitUserCryptoRequest, UpdateKdfResponse, UpdatePasswordResponse,
4};
5use bitwarden_crypto::{EncString, Kdf, UnsignedSharedKey};
6use bitwarden_encoding::B64;
7
8use crate::error::Result;
9
10#[allow(missing_docs)]
11#[derive(uniffi::Object)]
12pub struct CryptoClient(pub(crate) bitwarden_core::key_management::CryptoClient);
13
14#[uniffi::export(async_runtime = "tokio")]
15impl CryptoClient {
16 pub async fn initialize_user_crypto(&self, req: InitUserCryptoRequest) -> Result<()> {
19 Ok(self.0.initialize_user_crypto(req).await?)
20 }
21
22 pub async fn initialize_org_crypto(&self, req: InitOrgCryptoRequest) -> Result<()> {
25 Ok(self.0.initialize_org_crypto(req).await?)
26 }
27
28 pub async fn get_user_encryption_key(&self) -> Result<B64> {
31 Ok(self.0.get_user_encryption_key().await?)
32 }
33
34 pub fn make_update_password(&self, new_password: String) -> Result<UpdatePasswordResponse> {
38 Ok(self.0.make_update_password(new_password)?)
39 }
40
41 pub fn derive_pin_key(&self, pin: String) -> Result<DerivePinKeyResponse> {
45 Ok(self.0.derive_pin_key(pin)?)
46 }
47
48 pub fn derive_pin_user_key(&self, encrypted_pin: EncString) -> Result<EncString> {
51 Ok(self.0.derive_pin_user_key(encrypted_pin)?)
52 }
53
54 pub fn enroll_pin(&self, pin: String) -> Result<EnrollPinResponse> {
58 Ok(self.0.enroll_pin(pin)?)
59 }
60
61 pub fn enroll_pin_with_encrypted_pin(
65 &self,
66 encrypted_pin: EncString,
67 ) -> Result<EnrollPinResponse> {
68 Ok(self
69 .0
70 .enroll_pin_with_encrypted_pin(encrypted_pin.to_string())?)
71 }
72
73 pub fn enroll_admin_password_reset(&self, public_key: B64) -> Result<UnsignedSharedKey> {
74 Ok(self.0.enroll_admin_password_reset(public_key)?)
75 }
76
77 pub fn derive_key_connector(&self, request: DeriveKeyConnectorRequest) -> Result<B64> {
79 Ok(self.0.derive_key_connector(request)?)
80 }
81
82 pub fn make_update_kdf(&self, password: String, kdf: Kdf) -> Result<UpdateKdfResponse> {
86 Ok(self.0.make_update_kdf(password, kdf)?)
87 }
88}