Skip to content

Commit bb0ea1d

Browse files
committed
Improvements to Passkey uniffi API
1 parent c54a360 commit bb0ea1d

File tree

15 files changed

+989
-521
lines changed

15 files changed

+989
-521
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bitwarden-crypto/src/uniffi_support.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{num::NonZeroU32, str::FromStr};
22

33
use crate::{
4-
AsymmetricEncString, CryptoError, EncString, SensitiveString, UniffiCustomTypeConverter,
4+
AsymmetricEncString, CryptoError, EncString, SensitiveString, SensitiveVec, UniffiCustomTypeConverter
55
};
66

77
uniffi::custom_type!(NonZeroU32, u32);
@@ -59,3 +59,17 @@ impl UniffiCustomTypeConverter for SensitiveString {
5959
obj.expose().to_owned()
6060
}
6161
}
62+
63+
uniffi::custom_type!(SensitiveVec, Vec<u8>);
64+
65+
impl UniffiCustomTypeConverter for SensitiveVec {
66+
type Builtin = Vec<u8>;
67+
68+
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
69+
Ok(SensitiveVec::new(Box::new(val)))
70+
}
71+
72+
fn from_custom(obj: Self) -> Self::Builtin {
73+
obj.expose().to_owned()
74+
}
75+
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bitwarden::{
88
PublicKeyCredentialAuthenticatorAssertionResponse,
99
PublicKeyCredentialAuthenticatorAttestationResponse,
1010
},
11-
vault::{Cipher, CipherView, Fido2Credential, Fido2CredentialView},
11+
vault::{Cipher, CipherView, Fido2CredentialNewView, Fido2CredentialView},
1212
};
1313

1414
use crate::{error::Result, Client};
@@ -162,12 +162,12 @@ pub trait UserInterface: Send + Sync {
162162
) -> Result<CheckUserResult>;
163163
async fn pick_credential_for_authentication(
164164
&self,
165-
available_credentials: Vec<Cipher>,
165+
available_credentials: Vec<CipherView>,
166166
) -> Result<CipherViewWrapper>;
167167
async fn pick_credential_for_creation(
168168
&self,
169-
available_credentials: Vec<Cipher>,
170-
new_credential: Fido2Credential,
169+
available_credentials: Vec<CipherView>,
170+
new_credential: Fido2CredentialNewView,
171171
) -> Result<CipherViewWrapper>;
172172
}
173173

@@ -178,7 +178,7 @@ pub trait CredentialStore: Send + Sync {
178178
&self,
179179
ids: Option<Vec<Vec<u8>>>,
180180
rip_id: String,
181-
) -> Result<Vec<Cipher>>;
181+
) -> Result<Vec<CipherView>>;
182182

183183
async fn save_credential(&self, cred: Cipher) -> Result<()>;
184184
}
@@ -195,7 +195,7 @@ impl bitwarden::platform::fido2::CredentialStore for UniffiTraitBridge<&dyn Cred
195195
&self,
196196
ids: Option<Vec<Vec<u8>>>,
197197
rip_id: String,
198-
) -> BitResult<Vec<Cipher>> {
198+
) -> BitResult<Vec<CipherView>> {
199199
self.0
200200
.find_credentials(ids, rip_id)
201201
.await
@@ -234,7 +234,7 @@ impl bitwarden::platform::fido2::UserInterface for UniffiTraitBridge<&dyn UserIn
234234
}
235235
async fn pick_credential_for_authentication(
236236
&self,
237-
available_credentials: Vec<Cipher>,
237+
available_credentials: Vec<CipherView>,
238238
) -> BitResult<CipherView> {
239239
self.0
240240
.pick_credential_for_authentication(available_credentials)
@@ -244,8 +244,8 @@ impl bitwarden::platform::fido2::UserInterface for UniffiTraitBridge<&dyn UserIn
244244
}
245245
async fn pick_credential_for_creation(
246246
&self,
247-
available_credentials: Vec<Cipher>,
248-
new_credential: Fido2Credential,
247+
available_credentials: Vec<CipherView>,
248+
new_credential: Fido2CredentialNewView,
249249
) -> BitResult<CipherView> {
250250
self.0
251251
.pick_credential_for_creation(available_credentials, new_credential)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bitwarden_crypto::{AsymmetricEncString, EncString, SensitiveString};
1+
use bitwarden_crypto::{AsymmetricEncString, EncString, SensitiveString, SensitiveVec};
22
use uuid::Uuid;
33

44
// Forward the type definitions to the main bitwarden crate
@@ -7,4 +7,5 @@ uniffi::ffi_converter_forward!(DateTime, bitwarden::UniFfiTag, crate::UniFfiTag)
77
uniffi::ffi_converter_forward!(EncString, bitwarden::UniFfiTag, crate::UniFfiTag);
88
uniffi::ffi_converter_forward!(AsymmetricEncString, bitwarden::UniFfiTag, crate::UniFfiTag);
99
uniffi::ffi_converter_forward!(SensitiveString, bitwarden::UniFfiTag, crate::UniFfiTag);
10+
uniffi::ffi_converter_forward!(SensitiveVec, bitwarden::UniFfiTag, crate::UniFfiTag);
1011
uniffi::ffi_converter_forward!(Uuid, bitwarden::UniFfiTag, crate::UniFfiTag);

crates/bitwarden/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ internal = [
2424
mobile = [
2525
"internal",
2626
"dep:uniffi",
27+
"dep:passkey",
28+
"dep:coset",
2729
"bitwarden-crypto/mobile",
2830
"bitwarden-generators/mobile",
2931
] # Mobile-specific features
@@ -43,11 +45,13 @@ chrono = { version = ">=0.4.26, <0.5", features = [
4345
"serde",
4446
"std",
4547
], default-features = false }
48+
coset = { version = "0.3.7", optional = true }
4649
# We don't use this directly (it's used by rand), but we need it here to enable WASM support
4750
getrandom = { version = ">=0.2.9, <0.3", features = ["js"] }
4851
hmac = ">=0.12.1, <0.13"
4952
log = ">=0.4.18, <0.5"
50-
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "12da886102707f87ad97e499c857c0857ece0b85" }
53+
p256 = ">=0.13.2, <0.14"
54+
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "12da886102707f87ad97e499c857c0857ece0b85", optional = true }
5155
rand = ">=0.8.5, <0.9"
5256
reqwest = { version = ">=0.12, <0.13", features = [
5357
"http2",

0 commit comments

Comments
 (0)