diff --git a/crates/bitwarden-uniffi/src/error.rs b/crates/bitwarden-uniffi/src/error.rs index a7781a9ce..cf07a07a1 100644 --- a/crates/bitwarden-uniffi/src/error.rs +++ b/crates/bitwarden-uniffi/src/error.rs @@ -14,16 +14,17 @@ impl From for BitwardenError { } } -impl Into for BitwardenError { - fn into(self) -> bitwarden::error::Error { - match self { +impl From for bitwarden::error::Error { + fn from(val: BitwardenError) -> Self { + match val { BitwardenError::E(e) => e, } } } // Need to implement this From<> impl in order to handle unexpected callback errors. See the -// Callback Interfaces section of the handbook for more info. +// following page in the Uniffi user guide: +// impl From for BitwardenError { fn from(e: uniffi::UnexpectedUniFFICallbackError) -> Self { Self::E(bitwarden::error::Error::UniffiCallback(e)) diff --git a/crates/bitwarden-uniffi/src/platform/fido2.rs b/crates/bitwarden-uniffi/src/platform/fido2.rs index 854b7a98d..25756bdab 100644 --- a/crates/bitwarden-uniffi/src/platform/fido2.rs +++ b/crates/bitwarden-uniffi/src/platform/fido2.rs @@ -13,6 +13,8 @@ use bitwarden::{ use crate::{error::Result, Client}; +/// At the moment this is just a stub implementation that doesn't do anything. It's here to make +/// it possible to check the usability API on the native clients. #[derive(uniffi::Object)] pub struct ClientFido2(pub(crate) Arc); @@ -181,6 +183,10 @@ pub trait CredentialStore: Send + Sync { async fn save_credential(&self, cred: Cipher) -> Result<()>; } +// Because uniffi doesn't support external traits, we have to make a copy of the trait here. +// Ideally we'd want to implement the original trait for every item that implements our local copy, +// but the orphan rules don't allow us to blanket implement an external trait. So we have to wrap +// the trait in a newtype and implement the trait for the newtype. struct UniffiTraitBridge(T); #[async_trait::async_trait] @@ -201,6 +207,10 @@ impl bitwarden::platform::fido2::CredentialStore for UniffiTraitBridge<&dyn Cred } } +// Uniffi seems to have trouble generating code for Android when a local trait returns a type from +// an external crate. If the type is small we can just copy it over and convert back and forth, but +// Cipher is too big for that to be practical. So we wrap it in a newtype, which is local to the +// trait and so we can sidestep the Uniffi issue #[derive(uniffi::Record)] pub struct CipherViewWrapper { cipher: CipherView, diff --git a/crates/bitwarden/src/platform/client_platform.rs b/crates/bitwarden/src/platform/client_platform.rs index 93774c0eb..91c15c358 100644 --- a/crates/bitwarden/src/platform/client_platform.rs +++ b/crates/bitwarden/src/platform/client_platform.rs @@ -17,6 +17,8 @@ impl<'a> ClientPlatform<'a> { generate_user_fingerprint(self.client, fingerprint_material) } + /// At the moment this is just a stub implementation that doesn't do anything. It's here to make + /// it possible to check the usability API on the native clients. pub fn fido2(&'a mut self) -> ClientFido2<'a> { ClientFido2 { client: self.client,