bitwarden_crypto/
uniffi_support.rs

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