autofill/db/models/
credit_card.rs1use super::Metadata;
7use rusqlite::Row;
8use sync_guid::Guid;
9
10#[derive(Debug, Clone, Default)]
11pub struct UpdatableCreditCardFields {
12 pub cc_name: String,
13 pub cc_number_enc: String,
14 pub cc_number_last_4: String,
15 pub cc_exp_month: i64,
16 pub cc_exp_year: i64,
17 pub cc_type: String,
20}
21
22#[derive(Debug, Clone, Default)]
23pub struct CreditCard {
24 pub guid: String,
25 pub cc_name: String,
26 pub cc_number_enc: String,
27 pub cc_number_last_4: String,
28 pub cc_exp_month: i64,
29 pub cc_exp_year: i64,
30
31 pub cc_type: String,
34
35 pub time_created: i64,
37 pub time_last_used: Option<i64>,
38 pub time_last_modified: i64,
39 pub times_used: i64,
40}
41
42impl From<InternalCreditCard> for CreditCard {
45 fn from(icc: InternalCreditCard) -> Self {
46 CreditCard {
47 guid: icc.guid.to_string(),
48 cc_name: icc.cc_name,
49 cc_number_enc: icc.cc_number_enc,
50 cc_number_last_4: icc.cc_number_last_4,
51 cc_exp_month: icc.cc_exp_month,
52 cc_exp_year: icc.cc_exp_year,
53 cc_type: icc.cc_type,
54 time_created: u64::from(icc.metadata.time_created) as i64,
56 time_last_used: if icc.metadata.time_last_used.0 == 0 {
57 None
58 } else {
59 Some(icc.metadata.time_last_used.0 as i64)
60 },
61 time_last_modified: u64::from(icc.metadata.time_last_modified) as i64,
62 times_used: icc.metadata.times_used,
63 }
64 }
65}
66
67#[derive(Debug, Clone, Default)]
70pub struct InternalCreditCard {
71 pub guid: Guid,
72 pub cc_name: String,
73 pub cc_number_enc: String,
74 pub cc_number_last_4: String,
75 pub cc_exp_month: i64,
76 pub cc_exp_year: i64,
77 pub cc_type: String,
80 pub metadata: Metadata,
81}
82
83impl InternalCreditCard {
84 pub fn from_row(row: &Row<'_>) -> Result<InternalCreditCard, rusqlite::Error> {
85 Ok(Self {
86 guid: Guid::from_string(row.get("guid")?),
87 cc_name: row.get("cc_name")?,
88 cc_number_enc: row.get("cc_number_enc")?,
89 cc_number_last_4: row.get("cc_number_last_4")?,
90 cc_exp_month: row.get("cc_exp_month")?,
91 cc_exp_year: row.get("cc_exp_year")?,
92 cc_type: row.get("cc_type")?,
93 metadata: Metadata {
94 time_created: row.get("time_created")?,
95 time_last_used: row.get("time_last_used")?,
96 time_last_modified: row.get("time_last_modified")?,
97 times_used: row.get("times_used")?,
98 sync_change_counter: row.get("sync_change_counter")?,
99 },
100 })
101 }
102
103 pub fn has_scrubbed_data(&self) -> bool {
104 self.cc_number_enc.is_empty()
105 }
106}