bitwarden_core/
uniffi_support.rs

1//! This module contains custom type converters for Uniffi.
2
3use std::{num::NonZeroU32, str::FromStr};
4
5use bitwarden_crypto::safe;
6use bitwarden_uniffi_error::convert_result;
7use uuid::Uuid;
8
9use crate::key_management::SignedSecurityState;
10
11uniffi::use_remote_type!(bitwarden_crypto::NonZeroU32);
12uniffi::use_remote_type!(bitwarden_crypto::safe::PasswordProtectedKeyEnvelope);
13
14type DateTime = chrono::DateTime<chrono::Utc>;
15uniffi::custom_type!(DateTime, std::time::SystemTime, { remote });
16
17uniffi::custom_type!(Uuid, String, {
18    remote,
19    try_lift: |val| convert_result(Uuid::parse_str(&val)),
20    lower: |obj| obj.to_string(),
21});
22
23// Uniffi doesn't emit unused types, this is a dummy record to ensure that the custom type
24// converters are emitted
25#[allow(dead_code)]
26#[derive(uniffi::Record)]
27struct UniffiConverterDummyRecord {
28    uuid: Uuid,
29    date: DateTime,
30}
31
32uniffi::custom_type!(SignedSecurityState, String, {
33    try_lift: |val| {
34        convert_result(SignedSecurityState::from_str(&val))
35    },
36    lower: |obj| obj.into(),
37});