Skip to content

Commit

Permalink
Merge branch 'main' into ps/interior-mutability
Browse files Browse the repository at this point in the history
# Conflicts:
#	crates/bitwarden/src/client/client.rs
#	crates/bitwarden/src/platform/fido2/authenticator.rs
#	crates/bitwarden/src/platform/fido2/mod.rs
  • Loading branch information
dani-garcia committed Jun 13, 2024
2 parents 160d159 + e5a8dba commit 46f4b2c
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 100 deletions.
36 changes: 26 additions & 10 deletions crates/bitwarden-uniffi/src/platform/fido2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use bitwarden::{
error::Error,
platform::fido2::{
CheckUserOptions, ClientData, Fido2CallbackError as BitFido2CallbackError,
GetAssertionRequest, GetAssertionResult, MakeCredentialRequest, MakeCredentialResult,
Expand Down Expand Up @@ -60,9 +61,12 @@ impl ClientFido2Authenticator {
let fido2 = platform.fido2();

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

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L60-L61

Added lines #L60 - L61 were not covered by tests
let ui = UniffiTraitBridge(self.1.as_ref());
let cs = UniffiTraitBridge(self.2.as_ref());
let mut auth = fido2.create_authenticator(&ui, &cs)?;
let mut auth = fido2.create_authenticator(&ui, &cs);

let result = auth.make_credential(request).await?;
let result = auth
.make_credential(request)
.await
.map_err(Error::MakeCredential)?;
Ok(result)
}

Expand All @@ -71,9 +75,12 @@ impl ClientFido2Authenticator {
let fido2 = platform.fido2();

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

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L74-L75

Added lines #L74 - L75 were not covered by tests
let ui = UniffiTraitBridge(self.1.as_ref());
let cs = UniffiTraitBridge(self.2.as_ref());
let mut auth = fido2.create_authenticator(&ui, &cs)?;
let mut auth = fido2.create_authenticator(&ui, &cs);

let result = auth.get_assertion(request).await?;
let result = auth
.get_assertion(request)
.await
.map_err(Error::GetAssertion)?;
Ok(result)
}

Expand All @@ -85,9 +92,12 @@ impl ClientFido2Authenticator {
let fido2 = platform.fido2();

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

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L91-L92

Added lines #L91 - L92 were not covered by tests
let ui = UniffiTraitBridge(self.1.as_ref());
let cs = UniffiTraitBridge(self.2.as_ref());
let mut auth = fido2.create_authenticator(&ui, &cs)?;
let mut auth = fido2.create_authenticator(&ui, &cs);

let result = auth.silently_discover_credentials(rp_id).await?;
let result = auth
.silently_discover_credentials(rp_id)
.await
.map_err(Error::SilentlyDiscoverCredentials)?;
Ok(result)
}
}
Expand All @@ -107,9 +117,12 @@ impl ClientFido2Client {
let fido2 = platform.fido2();

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

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L116-L117

Added lines #L116 - L117 were not covered by tests
let ui = UniffiTraitBridge(self.0 .1.as_ref());
let cs = UniffiTraitBridge(self.0 .2.as_ref());
let mut client = fido2.create_client(&ui, &cs)?;
let mut client = fido2.create_client(&ui, &cs);

let result = client.register(origin, request, client_data).await?;
let result = client
.register(origin, request, client_data)
.await
.map_err(Error::Fido2Client)?;
Ok(result)
}

Expand All @@ -123,9 +136,12 @@ impl ClientFido2Client {
let fido2 = platform.fido2();

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

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/platform/fido2.rs#L135-L136

Added lines #L135 - L136 were not covered by tests
let ui = UniffiTraitBridge(self.0 .1.as_ref());
let cs = UniffiTraitBridge(self.0 .2.as_ref());
let mut client = fido2.create_client(&ui, &cs)?;
let mut client = fido2.create_client(&ui, &cs);

let result = client.authenticate(origin, request, client_data).await?;
let result = client
.authenticate(origin, request, client_data)
.await
.map_err(Error::Fido2Client)?;
Ok(result)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ impl Client {
}
}

pub(crate) fn get_encryption_settings(&self) -> Result<Arc<EncryptionSettings>> {
pub(crate) fn get_encryption_settings(&self) -> Result<Arc<EncryptionSettings>, VaultLocked> {
self.encryption_settings
.read()
.expect("RwLock is not poisoned")
.clone()
.ok_or(VaultLocked.into())
.ok_or(VaultLocked)
}

pub(crate) fn set_login_method(&self, login_method: LoginMethod) {
Expand Down
27 changes: 14 additions & 13 deletions crates/bitwarden/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use bitwarden_api_identity::apis::Error as IdentityError;
use bitwarden_exporters::ExportError;
#[cfg(feature = "internal")]
use bitwarden_generators::{PassphraseError, PasswordError, UsernameError};
#[cfg(feature = "uniffi")]
use passkey::client::WebauthnError;
use reqwest::StatusCode;
use thiserror::Error;

Expand Down Expand Up @@ -81,29 +79,32 @@ pub enum Error {
#[error(transparent)]
ExportError(#[from] ExportError),

#[cfg(feature = "uniffi")]
#[error("Webauthn error: {0:?}")]
WebauthnError(WebauthnError),
// Fido
#[cfg(all(feature = "uniffi", feature = "internal"))]
#[error(transparent)]
MakeCredential(#[from] crate::platform::fido2::MakeCredentialError),
#[cfg(all(feature = "uniffi", feature = "internal"))]
#[error(transparent)]
GetAssertion(#[from] crate::platform::fido2::GetAssertionError),
#[cfg(all(feature = "uniffi", feature = "internal"))]
#[error(transparent)]
SilentlyDiscoverCredentials(#[from] crate::platform::fido2::SilentlyDiscoverCredentialsError),
#[cfg(all(feature = "uniffi", feature = "internal"))]
#[error(transparent)]
Fido2Client(#[from] crate::platform::fido2::Fido2ClientError),

#[cfg(feature = "uniffi")]
#[error("Uniffi callback error: {0}")]
UniffiCallbackError(#[from] uniffi::UnexpectedUniFFICallbackError),

#[cfg(feature = "uniffi")]
#[cfg(all(feature = "uniffi", feature = "internal"))]
#[error("Fido2 Callback error: {0:?}")]
Fido2CallbackError(#[from] crate::platform::fido2::Fido2CallbackError),

#[error("Internal error: {0}")]
Internal(Cow<'static, str>),
}

#[cfg(feature = "uniffi")]
impl From<WebauthnError> for Error {
fn from(e: WebauthnError) -> Self {
Self::WebauthnError(e)
}
}

impl From<String> for Error {
fn from(s: String) -> Self {
Self::Internal(s.into())
Expand Down
Loading

0 comments on commit 46f4b2c

Please sign in to comment.