Skip to content

Commit 82595fe

Browse files
authored
[PM-20957] Update UniFFI to 0.29.1 (#256)
## 🎟️ Tracking https://bitwarden.atlassian.net/browse/PM-20957 ## 📔 Objective This replaces the renovate PR as the changes are fairly big. Update UniFFI to version 0.29.1. This requires bumping MSRV to 1.82, as that's the requirement from UniFFI. The migration consists of a few parts: - Replaced all the uses of `UniffiCustomTypeConverter` by the simpler `custom_type!` macro. Note that for types defined in other crates, we still use the same macro, but with the `remote,` value added. - Reworked all the uses of `ffi_converter_forward!`: - If they were forwarding bitwarden defined types, they aren't needed anymore. - If they were forwarding types from third party crates, they were replaced by `use_remote_type!` - Replaced a usage of `uniffi::deps::log` by the `log` crate directly. - While replacing the implementation of `LinkedId`, I've noticed that we had two implementations of `TryFrom<U32>`, the one used by uniffi based on deserialize, and a hardcoded map. I've combined them in one using the deserialize strategy. I've tested this on the Android and iOS native apps, and they both compile and decrypt the vault without issues. ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or ⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes
1 parent 91e3e2a commit 82595fe

File tree

12 files changed

+115
-255
lines changed

12 files changed

+115
-255
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version = "1.0.0"
99
authors = ["Bitwarden Inc"]
1010
edition = "2021"
1111
# Important: Changing rust-version should be considered a breaking change
12-
rust-version = "1.75"
12+
rust-version = "1.82"
1313
homepage = "https://bitwarden.com"
1414
repository = "https://github.com/bitwarden/sdk-internal"
1515
license-file = "LICENSE"
@@ -58,7 +58,7 @@ tokio = { version = "1.36.0", features = ["macros"] }
5858
tsify-next = { version = ">=0.5.4, <0.6", features = [
5959
"js",
6060
], default-features = false }
61-
uniffi = "=0.28.3"
61+
uniffi = "=0.29.1"
6262
uuid = { version = ">=1.3.3, <2.0", features = ["serde", "v4", "js"] }
6363
validator = { version = ">=0.18.1, <0.20", features = ["derive"] }
6464
wasm-bindgen = { version = ">=0.2.91, <0.3", features = ["serde-serialize"] }

crates/bitwarden-core/src/uniffi_support.rs

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,18 @@
22
33
use std::num::NonZeroU32;
44

5-
use bitwarden_crypto::{EncString, UnsignedSharedKey};
65
use uuid::Uuid;
76

8-
use crate::UniffiCustomTypeConverter;
9-
10-
uniffi::ffi_converter_forward!(NonZeroU32, bitwarden_crypto::UniFfiTag, crate::UniFfiTag);
11-
uniffi::ffi_converter_forward!(EncString, bitwarden_crypto::UniFfiTag, crate::UniFfiTag);
12-
uniffi::ffi_converter_forward!(
13-
UnsignedSharedKey,
14-
bitwarden_crypto::UniFfiTag,
15-
crate::UniFfiTag
16-
);
7+
uniffi::use_remote_type!(bitwarden_crypto::NonZeroU32);
178

189
type DateTime = chrono::DateTime<chrono::Utc>;
19-
uniffi::custom_type!(DateTime, std::time::SystemTime);
20-
21-
impl UniffiCustomTypeConverter for chrono::DateTime<chrono::Utc> {
22-
type Builtin = std::time::SystemTime;
23-
24-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
25-
Ok(Self::from(val))
26-
}
27-
28-
fn from_custom(obj: Self) -> Self::Builtin {
29-
obj.into()
30-
}
31-
}
10+
uniffi::custom_type!(DateTime, std::time::SystemTime, { remote });
3211

33-
uniffi::custom_type!(Uuid, String);
34-
35-
impl UniffiCustomTypeConverter for Uuid {
36-
type Builtin = String;
37-
38-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
39-
Uuid::parse_str(val.as_str()).map_err(|e| e.into())
40-
}
41-
42-
fn from_custom(obj: Self) -> Self::Builtin {
43-
obj.to_string()
44-
}
45-
}
12+
uniffi::custom_type!(Uuid, String, {
13+
remote,
14+
try_lift: |val| Uuid::parse_str(val.as_str()).map_err(|e| e.into()),
15+
lower: |obj| obj.to_string(),
16+
});
4617

4718
// Uniffi doesn't emit unused types, this is a dummy record to ensure that the custom type
4819
// converters are emitted
Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,25 @@
11
use std::{num::NonZeroU32, str::FromStr};
22

3-
use crate::{CryptoError, EncString, UniffiCustomTypeConverter, UnsignedSharedKey};
4-
5-
uniffi::custom_type!(NonZeroU32, u32);
6-
7-
impl UniffiCustomTypeConverter for NonZeroU32 {
8-
type Builtin = u32;
9-
10-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
11-
Self::new(val).ok_or(CryptoError::ZeroNumber.into())
12-
}
13-
14-
fn from_custom(obj: Self) -> Self::Builtin {
15-
obj.get()
16-
}
17-
}
18-
19-
uniffi::custom_type!(EncString, String);
20-
21-
impl UniffiCustomTypeConverter for EncString {
22-
type Builtin = String;
23-
24-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
25-
val.parse().map_err(|e: CryptoError| e.into())
26-
}
27-
28-
fn from_custom(obj: Self) -> Self::Builtin {
29-
obj.to_string()
30-
}
31-
}
32-
33-
uniffi::custom_type!(UnsignedSharedKey, String);
34-
35-
impl UniffiCustomTypeConverter for UnsignedSharedKey {
36-
type Builtin = String;
37-
38-
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
39-
Self::from_str(&val).map_err(|e| e.into())
40-
}
41-
42-
fn from_custom(obj: Self) -> Self::Builtin {
43-
obj.to_string()
44-
}
45-
}
3+
use crate::{CryptoError, EncString, UnsignedSharedKey};
4+
5+
uniffi::custom_type!(NonZeroU32, u32, {
6+
remote,
7+
try_lift: |val| {
8+
NonZeroU32::new(val).ok_or(CryptoError::ZeroNumber.into())
9+
},
10+
lower: |obj| obj.get(),
11+
});
12+
13+
uniffi::custom_type!(EncString, String, {
14+
try_lift: |val| {
15+
EncString::from_str(&val).map_err(|e: CryptoError| e.into())
16+
},
17+
lower: |obj| obj.to_string(),
18+
});
19+
20+
uniffi::custom_type!(UnsignedSharedKey, String, {
21+
try_lift: |val| {
22+
UnsignedSharedKey::from_str(&val).map_err(|e: CryptoError| e.into())
23+
},
24+
lower: |obj| obj.to_string(),
25+
});

0 commit comments

Comments
 (0)