Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bitwarden/sdk into ps/passkey-ios
Browse files Browse the repository at this point in the history
# Conflicts:
#	crates/bitwarden-uniffi/src/error.rs
#	crates/bitwarden-uniffi/src/platform/fido2.rs
#	crates/bitwarden/src/platform/client_platform.rs
  • Loading branch information
Hinton committed May 3, 2024
2 parents 2e67c00 + 57fa7fa commit fe8cc92
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 5 additions & 4 deletions crates/bitwarden-uniffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ impl From<bitwarden::error::Error> for BitwardenError {
}
}

impl Into<bitwarden::error::Error> for BitwardenError {
fn into(self) -> bitwarden::error::Error {
match self {
impl From<BitwardenError> 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:
// <https://mozilla.github.io/uniffi-rs/foreign_traits.html#error-handling>
impl From<uniffi::UnexpectedUniFFICallbackError> for BitwardenError {
fn from(e: uniffi::UnexpectedUniFFICallbackError) -> Self {
Self::E(bitwarden::error::Error::UniffiCallback(e))
Expand Down
10 changes: 10 additions & 0 deletions crates/bitwarden-uniffi/src/platform/fido2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Client>);

Expand Down Expand Up @@ -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>(T);

#[async_trait::async_trait]
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden/src/platform/client_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fe8cc92

Please sign in to comment.