autofill/db/models/
credit_card.rsuse super::Metadata;
use rusqlite::Row;
use sync_guid::Guid;
#[derive(Debug, Clone, Default)]
pub struct UpdatableCreditCardFields {
pub cc_name: String,
pub cc_number_enc: String,
pub cc_number_last_4: String,
pub cc_exp_month: i64,
pub cc_exp_year: i64,
pub cc_type: String,
}
#[derive(Debug, Clone, Default)]
pub struct CreditCard {
pub guid: String,
pub cc_name: String,
pub cc_number_enc: String,
pub cc_number_last_4: String,
pub cc_exp_month: i64,
pub cc_exp_year: i64,
pub cc_type: String,
pub time_created: i64,
pub time_last_used: Option<i64>,
pub time_last_modified: i64,
pub times_used: i64,
}
impl From<InternalCreditCard> for CreditCard {
fn from(icc: InternalCreditCard) -> Self {
CreditCard {
guid: icc.guid.to_string(),
cc_name: icc.cc_name,
cc_number_enc: icc.cc_number_enc,
cc_number_last_4: icc.cc_number_last_4,
cc_exp_month: icc.cc_exp_month,
cc_exp_year: icc.cc_exp_year,
cc_type: icc.cc_type,
time_created: u64::from(icc.metadata.time_created) as i64,
time_last_used: if icc.metadata.time_last_used.0 == 0 {
None
} else {
Some(icc.metadata.time_last_used.0 as i64)
},
time_last_modified: u64::from(icc.metadata.time_last_modified) as i64,
times_used: icc.metadata.times_used,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct InternalCreditCard {
pub guid: Guid,
pub cc_name: String,
pub cc_number_enc: String,
pub cc_number_last_4: String,
pub cc_exp_month: i64,
pub cc_exp_year: i64,
pub cc_type: String,
pub metadata: Metadata,
}
impl InternalCreditCard {
pub fn from_row(row: &Row<'_>) -> Result<InternalCreditCard, rusqlite::Error> {
Ok(Self {
guid: Guid::from_string(row.get("guid")?),
cc_name: row.get("cc_name")?,
cc_number_enc: row.get("cc_number_enc")?,
cc_number_last_4: row.get("cc_number_last_4")?,
cc_exp_month: row.get("cc_exp_month")?,
cc_exp_year: row.get("cc_exp_year")?,
cc_type: row.get("cc_type")?,
metadata: Metadata {
time_created: row.get("time_created")?,
time_last_used: row.get("time_last_used")?,
time_last_modified: row.get("time_last_modified")?,
times_used: row.get("times_used")?,
sync_change_counter: row.get("sync_change_counter")?,
},
})
}
pub fn has_scrubbed_data(&self) -> bool {
self.cc_number_enc.is_empty()
}
}