Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/bitwarden-core/src/uniffi_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@ uniffi::custom_type!(Uuid, String, {
lower: |obj| obj.to_string(),
});

type NaiveDate = chrono::NaiveDate;
uniffi::custom_type!(NaiveDate, String, {
remote,
try_lift: |val| convert_result(NaiveDate::from_str(&val)),
lower: |obj| obj.to_string(),
});

// Uniffi doesn't emit unused types, this is a dummy record to ensure that the custom type
// converters are emitted
#[allow(dead_code)]
#[derive(uniffi::Record)]
struct UniffiConverterDummyRecord {
uuid: Uuid,
date: DateTime,
naive_date: NaiveDate,
}

uniffi::custom_type!(SignedSecurityState, String, {
Expand Down
6 changes: 6 additions & 0 deletions crates/bitwarden-core/uniffi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ android = true
# Temporary workaround for https://github.com/mozilla/uniffi-rs/issues/2740
omit_checksums = true

[bindings.kotlin.custom_types.NaiveDate]
type_name = "LocalDate"
imports = ["java.time.LocalDate"]
into_custom = "LocalDate.parse({})"
from_custom = "{}.toString()"

[bindings.swift]
ffi_module_name = "BitwardenCoreFFI"
module_name = "BitwardenCore"
Expand Down
3 changes: 3 additions & 0 deletions crates/bitwarden-uniffi/src/uniffi_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use uuid::Uuid;
type DateTime = chrono::DateTime<chrono::Utc>;
uniffi::use_remote_type!(bitwarden_core::DateTime);

type NaiveDate = chrono::NaiveDate;
uniffi::use_remote_type!(bitwarden_core::NaiveDate);

uniffi::use_remote_type!(bitwarden_core::Uuid);

uniffi::use_remote_type!(bitwarden_crypto::safe::PasswordProtectedKeyEnvelope);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
use super::{DriversLicenseDataV1, DriversLicenseView};

impl_bidirectional_from!(
DriversLicenseView,
DriversLicenseDataV1,
[
first_name,
middle_name,
last_name,
date_of_birth,
license_number,
issuing_country,
issuing_state,
issue_date,
expiration_date,
issuing_authority,
license_class,
]
);
impl From<&DriversLicenseView> for DriversLicenseDataV1 {
fn from(src: &DriversLicenseView) -> Self {
Self {
first_name: src.first_name.clone(),
middle_name: src.middle_name.clone(),
last_name: src.last_name.clone(),
date_of_birth: src.date_of_birth.map(|d| d.to_string()),
license_number: src.license_number.clone(),
issuing_country: src.issuing_country.clone(),
issuing_state: src.issuing_state.clone(),
issue_date: src.issue_date.map(|d| d.to_string()),
expiration_date: src.expiration_date.map(|d| d.to_string()),
issuing_authority: src.issuing_authority.clone(),
license_class: src.license_class.clone(),
}
}
}

impl From<&DriversLicenseDataV1> for DriversLicenseView {
fn from(src: &DriversLicenseDataV1) -> Self {
Self {
first_name: src.first_name.clone(),
middle_name: src.middle_name.clone(),
last_name: src.last_name.clone(),
date_of_birth: src.date_of_birth.as_deref().and_then(|s| s.parse().ok()),
license_number: src.license_number.clone(),
issuing_country: src.issuing_country.clone(),
issuing_state: src.issuing_state.clone(),
issue_date: src.issue_date.as_deref().and_then(|s| s.parse().ok()),
expiration_date: src.expiration_date.as_deref().and_then(|s| s.parse().ok()),
issuing_authority: src.issuing_authority.clone(),
license_class: src.license_class.clone(),
}
}
}

#[cfg(test)]
mod tests {
Expand All @@ -36,12 +54,12 @@ mod tests {
first_name: Some("John".to_string()),
middle_name: Some("Michael".to_string()),
last_name: Some("Doe".to_string()),
date_of_birth: Some("1985-06-15".to_string()),
date_of_birth: chrono::NaiveDate::from_ymd_opt(1985, 6, 15),
license_number: Some("DL-987654".to_string()),
issuing_country: Some("US".to_string()),
issuing_state: Some("NY".to_string()),
issue_date: Some("2020-01-01".to_string()),
expiration_date: Some("2028-01-01".to_string()),
issue_date: chrono::NaiveDate::from_ymd_opt(2020, 1, 1),
expiration_date: chrono::NaiveDate::from_ymd_opt(2028, 1, 1),
issuing_authority: Some("NY DMV".to_string()),
license_class: Some("D".to_string()),
}),
Expand Down
64 changes: 42 additions & 22 deletions crates/bitwarden-vault/src/cipher/blob/conversions/passport.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
use super::{PassportDataV1, PassportView};

impl_bidirectional_from!(
PassportView,
PassportDataV1,
[
surname,
given_name,
date_of_birth,
sex,
birth_place,
nationality,
issuing_country,
passport_number,
passport_type,
national_identification_number,
issuing_authority,
issue_date,
expiration_date,
]
);
impl From<&PassportView> for PassportDataV1 {
fn from(src: &PassportView) -> Self {
Self {
surname: src.surname.clone(),
given_name: src.given_name.clone(),
date_of_birth: src.date_of_birth.map(|d| d.to_string()),
sex: src.sex.clone(),
birth_place: src.birth_place.clone(),
nationality: src.nationality.clone(),
issuing_country: src.issuing_country.clone(),
passport_number: src.passport_number.clone(),
passport_type: src.passport_type.clone(),
national_identification_number: src.national_identification_number.clone(),
issuing_authority: src.issuing_authority.clone(),
issue_date: src.issue_date.map(|d| d.to_string()),
expiration_date: src.expiration_date.map(|d| d.to_string()),
}
}
}

impl From<&PassportDataV1> for PassportView {
fn from(src: &PassportDataV1) -> Self {
Self {
surname: src.surname.clone(),
given_name: src.given_name.clone(),
date_of_birth: src.date_of_birth.as_deref().and_then(|s| s.parse().ok()),
sex: src.sex.clone(),
birth_place: src.birth_place.clone(),
nationality: src.nationality.clone(),
issuing_country: src.issuing_country.clone(),
passport_number: src.passport_number.clone(),
passport_type: src.passport_type.clone(),
national_identification_number: src.national_identification_number.clone(),
issuing_authority: src.issuing_authority.clone(),
issue_date: src.issue_date.as_deref().and_then(|s| s.parse().ok()),
expiration_date: src.expiration_date.as_deref().and_then(|s| s.parse().ok()),
}
}
}

#[cfg(test)]
mod tests {
Expand All @@ -37,7 +57,7 @@ mod tests {
passport: Some(PassportView {
surname: Some("Doe".to_string()),
given_name: Some("Jane".to_string()),
date_of_birth: Some("1990-01-01".to_string()),
date_of_birth: chrono::NaiveDate::from_ymd_opt(1990, 1, 1),
sex: Some("F".to_string()),
birth_place: Some("New York".to_string()),
nationality: Some("American".to_string()),
Expand All @@ -46,8 +66,8 @@ mod tests {
passport_type: Some("P".to_string()),
national_identification_number: Some("123-45-6789".to_string()),
issuing_authority: Some("US State Department".to_string()),
issue_date: Some("2020-01-01".to_string()),
expiration_date: Some("2030-01-01".to_string()),
issue_date: chrono::NaiveDate::from_ymd_opt(2020, 1, 1),
expiration_date: chrono::NaiveDate::from_ymd_opt(2030, 1, 1),
}),
..create_shell_cipher_view(CipherType::Passport)
};
Expand Down
12 changes: 6 additions & 6 deletions crates/bitwarden-vault/src/cipher/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,7 @@ mod tests {
let passport = passport::PassportView {
given_name: Some("Jane".to_string()),
surname: Some("Doe".to_string()),
date_of_birth: Some("1990-01-01".to_string()),
date_of_birth: chrono::NaiveDate::from_ymd_opt(1990, 1, 1),
sex: Some("F".to_string()),
birth_place: Some("New York".to_string()),
nationality: Some("American".to_string()),
Expand All @@ -3010,8 +3010,8 @@ mod tests {
passport_type: Some("P".to_string()),
national_identification_number: Some("123-45-6789".to_string()),
issuing_authority: Some("US State Department".to_string()),
issue_date: Some("2020-01-01".to_string()),
expiration_date: Some("2030-01-01".to_string()),
issue_date: chrono::NaiveDate::from_ymd_opt(2020, 1, 1),
expiration_date: chrono::NaiveDate::from_ymd_opt(2030, 1, 1),
};

let cipher_view = CipherView {
Expand All @@ -3038,12 +3038,12 @@ mod tests {
first_name: Some("John".to_string()),
middle_name: Some("Michael".to_string()),
last_name: Some("Doe".to_string()),
date_of_birth: Some("1985-06-15".to_string()),
date_of_birth: chrono::NaiveDate::from_ymd_opt(1985, 6, 15),
license_number: Some("DL-987654".to_string()),
issuing_country: Some("US".to_string()),
issuing_state: Some("NY".to_string()),
issue_date: Some("2020-01-01".to_string()),
expiration_date: Some("2028-01-01".to_string()),
issue_date: chrono::NaiveDate::from_ymd_opt(2020, 1, 1),
expiration_date: chrono::NaiveDate::from_ymd_opt(2028, 1, 1),
issuing_authority: Some("NY DMV".to_string()),
license_class: Some("D".to_string()),
};
Expand Down
46 changes: 34 additions & 12 deletions crates/bitwarden-vault/src/cipher/drivers_license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bitwarden_crypto::{
CompositeEncryptable, CryptoError, Decryptable, EncString, KeyStoreContext,
PrimitiveEncryptable,
};
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
#[cfg(feature = "wasm")]
use tsify::Tsify;
Expand Down Expand Up @@ -38,12 +39,12 @@ pub struct DriversLicenseView {
pub first_name: Option<String>,
pub middle_name: Option<String>,
pub last_name: Option<String>,
pub date_of_birth: Option<String>,
pub date_of_birth: Option<NaiveDate>,
pub license_number: Option<String>,
pub issuing_country: Option<String>,
pub issuing_state: Option<String>,
pub issue_date: Option<String>,
pub expiration_date: Option<String>,
pub issue_date: Option<NaiveDate>,
pub expiration_date: Option<NaiveDate>,
pub issuing_authority: Option<String>,
pub license_class: Option<String>,
}
Expand All @@ -58,12 +59,18 @@ impl CompositeEncryptable<KeySlotIds, SymmetricKeySlotId, DriversLicense> for Dr
first_name: self.first_name.encrypt(ctx, key)?,
middle_name: self.middle_name.encrypt(ctx, key)?,
last_name: self.last_name.encrypt(ctx, key)?,
date_of_birth: self.date_of_birth.encrypt(ctx, key)?,
date_of_birth: self
.date_of_birth
.map(|d| d.to_string())
.encrypt(ctx, key)?,
license_number: self.license_number.encrypt(ctx, key)?,
issuing_country: self.issuing_country.encrypt(ctx, key)?,
issuing_state: self.issuing_state.encrypt(ctx, key)?,
issue_date: self.issue_date.encrypt(ctx, key)?,
expiration_date: self.expiration_date.encrypt(ctx, key)?,
issue_date: self.issue_date.map(|d| d.to_string()).encrypt(ctx, key)?,
expiration_date: self
.expiration_date
.map(|d| d.to_string())
.encrypt(ctx, key)?,
issuing_authority: self.issuing_authority.encrypt(ctx, key)?,
license_class: self.license_class.encrypt(ctx, key)?,
})
Expand All @@ -80,12 +87,27 @@ impl Decryptable<KeySlotIds, SymmetricKeySlotId, DriversLicenseView> for Drivers
first_name: self.first_name.decrypt(ctx, key).ok().flatten(),
middle_name: self.middle_name.decrypt(ctx, key).ok().flatten(),
last_name: self.last_name.decrypt(ctx, key).ok().flatten(),
date_of_birth: self.date_of_birth.decrypt(ctx, key).ok().flatten(),
date_of_birth: self
.date_of_birth
.decrypt(ctx, key)
.ok()
.flatten()
.and_then(|s: String| s.parse().ok()),
license_number: self.license_number.decrypt(ctx, key).ok().flatten(),
issuing_country: self.issuing_country.decrypt(ctx, key).ok().flatten(),
issuing_state: self.issuing_state.decrypt(ctx, key).ok().flatten(),
issue_date: self.issue_date.decrypt(ctx, key).ok().flatten(),
expiration_date: self.expiration_date.decrypt(ctx, key).ok().flatten(),
issue_date: self
.issue_date
.decrypt(ctx, key)
.ok()
.flatten()
.and_then(|s: String| s.parse().ok()),
expiration_date: self
.expiration_date
.decrypt(ctx, key)
.ok()
.flatten()
.and_then(|s: String| s.parse().ok()),
issuing_authority: self.issuing_authority.decrypt(ctx, key).ok().flatten(),
license_class: self.license_class.decrypt(ctx, key).ok().flatten(),
})
Expand Down Expand Up @@ -192,12 +214,12 @@ mod tests {
first_name: Some("John".to_string()),
middle_name: Some("Michael".to_string()),
last_name: Some("Doe".to_string()),
date_of_birth: Some("1985-06-15".to_string()),
date_of_birth: NaiveDate::from_ymd_opt(1985, 6, 15),
license_number: Some("DL-987654".to_string()),
issuing_country: Some("US".to_string()),
issuing_state: Some("NY".to_string()),
issue_date: Some("2020-01-01".to_string()),
expiration_date: Some("2028-01-01".to_string()),
issue_date: NaiveDate::from_ymd_opt(2020, 1, 1),
expiration_date: NaiveDate::from_ymd_opt(2028, 1, 1),
issuing_authority: Some("NY DMV".to_string()),
license_class: Some("D".to_string()),
}
Expand Down
Loading
Loading