bitwarden_crypto/
uniffi_support.rs

1use std::{num::NonZeroU32, str::FromStr};
2
3use bitwarden_uniffi_error::convert_result;
4
5use crate::{CryptoError, EncString, SignedPublicKey, UnsignedSharedKey};
6
7uniffi::custom_type!(NonZeroU32, u32, {
8    remote,
9    try_lift: |val| {
10        convert_result(NonZeroU32::new(val).ok_or(CryptoError::ZeroNumber))
11    },
12    lower: |obj| obj.get(),
13});
14
15uniffi::custom_type!(EncString, String, {
16    try_lift: |val| {
17        convert_result(EncString::from_str(&val))
18    },
19    lower: |obj| obj.to_string(),
20});
21
22uniffi::custom_type!(UnsignedSharedKey, String, {
23    try_lift: |val| {
24        convert_result(UnsignedSharedKey::from_str(&val))
25    },
26    lower: |obj| obj.to_string(),
27});
28
29uniffi::custom_type!(SignedPublicKey, String, {
30    try_lift: |val| {
31        convert_result(SignedPublicKey::from_str(&val))
32    },
33    lower: |obj| obj.into(),
34});