bitwarden_uniffi/
crypto.rsuse std::sync::Arc;
use bitwarden::{
mobile::crypto::{
DeriveKeyConnectorRequest, DerivePinKeyResponse, InitOrgCryptoRequest,
InitUserCryptoRequest, UpdatePasswordResponse,
},
Error,
};
use bitwarden_crypto::{AsymmetricEncString, EncString};
use crate::{error::Result, Client};
#[derive(uniffi::Object)]
pub struct ClientCrypto(pub(crate) Arc<Client>);
#[uniffi::export(async_runtime = "tokio")]
impl ClientCrypto {
pub async fn initialize_user_crypto(&self, req: InitUserCryptoRequest) -> Result<()> {
Ok(self
.0
.0
.crypto()
.initialize_user_crypto(req)
.await
.map_err(Error::EncryptionSettings)?)
}
pub async fn initialize_org_crypto(&self, req: InitOrgCryptoRequest) -> Result<()> {
Ok(self
.0
.0
.crypto()
.initialize_org_crypto(req)
.await
.map_err(Error::EncryptionSettings)?)
}
pub async fn get_user_encryption_key(&self) -> Result<String> {
Ok(self.0 .0.crypto().get_user_encryption_key().await?)
}
pub fn update_password(&self, new_password: String) -> Result<UpdatePasswordResponse> {
Ok(self.0 .0.crypto().update_password(new_password)?)
}
pub fn derive_pin_key(&self, pin: String) -> Result<DerivePinKeyResponse> {
Ok(self.0 .0.crypto().derive_pin_key(pin)?)
}
pub fn derive_pin_user_key(&self, encrypted_pin: EncString) -> Result<EncString> {
Ok(self.0 .0.crypto().derive_pin_user_key(encrypted_pin)?)
}
pub fn enroll_admin_password_reset(&self, public_key: String) -> Result<AsymmetricEncString> {
Ok(self.0 .0.crypto().enroll_admin_password_reset(public_key)?)
}
pub fn derive_key_connector(&self, request: DeriveKeyConnectorRequest) -> Result<String> {
Ok(self.0 .0.crypto().derive_key_connector(request)?)
}
}