Skip to content

Commit

Permalink
Fix kotlin uniffi errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia committed May 3, 2024
1 parent 2ce8e3d commit dba3fda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
26 changes: 22 additions & 4 deletions crates/bitwarden-uniffi/src/platform/fido2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use bitwarden::{
error::Result as BitResult,
platform::fido2::{
CheckUserOptions, CheckUserResult, ClientData, GetAssertionRequest, GetAssertionResult,
CheckUserOptions, ClientData, GetAssertionRequest, GetAssertionResult,
MakeCredentialRequest, MakeCredentialResult,
PublicKeyCredentialAuthenticatorAssertionResponse,
PublicKeyCredentialAuthenticatorAttestationResponse,
Expand Down Expand Up @@ -143,6 +143,13 @@ impl ClientFido2Client {
// Note that uniffi doesn't support external traits for now it seems, so we have to duplicate them
// here.

#[allow(dead_code)]
#[derive(uniffi::Record)]
pub struct CheckUserResult {
user_present: bool,
user_verified: bool,
}

#[uniffi::export(with_foreign)]

Check warning on line 153 in crates/bitwarden-uniffi/src/platform/fido2.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L153

Added line #L153 was not covered by tests
#[async_trait::async_trait]
pub trait UserInterface: Send + Sync {
Expand All @@ -154,12 +161,12 @@ pub trait UserInterface: Send + Sync {
async fn pick_credential_for_authentication(
&self,
available_credentials: Vec<Cipher>,
) -> Result<CipherView>;
) -> Result<CipherViewWrapper>;
async fn pick_credential_for_creation(
&self,
available_credentials: Vec<Cipher>,
new_credential: Fido2Credential,
) -> Result<CipherView>;
) -> Result<CipherViewWrapper>;
}

#[uniffi::export(with_foreign)]

Check warning on line 172 in crates/bitwarden-uniffi/src/platform/fido2.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L172

Added line #L172 was not covered by tests
Expand Down Expand Up @@ -194,16 +201,25 @@ impl bitwarden::platform::fido2::CredentialStore for UniffiTraitBridge<&dyn Cred
}

Check warning on line 201 in crates/bitwarden-uniffi/src/platform/fido2.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L199-L201

Added lines #L199 - L201 were not covered by tests
}

#[derive(uniffi::Record)]
pub struct CipherViewWrapper {
cipher: CipherView,
}

#[async_trait::async_trait]
impl bitwarden::platform::fido2::UserInterface for UniffiTraitBridge<&dyn UserInterface> {
async fn check_user(
&self,
options: CheckUserOptions,
credential: Option<CipherView>,
) -> BitResult<CheckUserResult> {
) -> BitResult<bitwarden::platform::fido2::CheckUserResult> {
self.0
.check_user(options, credential)
.await
.map(|r| bitwarden::platform::fido2::CheckUserResult {
user_present: r.user_present,
user_verified: r.user_verified,
})
.map_err(Into::into)
}

Check warning on line 224 in crates/bitwarden-uniffi/src/platform/fido2.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L215-L224

Added lines #L215 - L224 were not covered by tests
async fn pick_credential_for_authentication(
Expand All @@ -213,6 +229,7 @@ impl bitwarden::platform::fido2::UserInterface for UniffiTraitBridge<&dyn UserIn
self.0
.pick_credential_for_authentication(available_credentials)
.await
.map(|v| v.cipher)
.map_err(Into::into)
}

Check warning on line 234 in crates/bitwarden-uniffi/src/platform/fido2.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L228-L234

Added lines #L228 - L234 were not covered by tests
async fn pick_credential_for_creation(
Expand All @@ -223,6 +240,7 @@ impl bitwarden::platform::fido2::UserInterface for UniffiTraitBridge<&dyn UserIn
self.0
.pick_credential_for_creation(available_credentials, new_credential)
.await
.map(|v| v.cipher)
.map_err(Into::into)
}

Check warning on line 245 in crates/bitwarden-uniffi/src/platform/fido2.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L239-L245

Added lines #L239 - L245 were not covered by tests
}
6 changes: 2 additions & 4 deletions crates/bitwarden/src/platform/fido2/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ pub enum Verification {
Required,
}

#[allow(dead_code)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct CheckUserResult {
user_present: bool,
user_verified: bool,
pub user_present: bool,
pub user_verified: bool,
}

0 comments on commit dba3fda

Please sign in to comment.