Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encryption model optionals #267

Merged
merged 1 commit into from
Oct 5, 2023
Merged
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
20 changes: 12 additions & 8 deletions crates/bitwarden/src/vault/cipher/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ pub struct Cipher {
pub view_password: bool,
pub local_data: Option<LocalData>,

pub attachments: Vec<attachment::Attachment>,
pub fields: Vec<field::Field>,
pub password_history: Vec<password_history::PasswordHistory>,
pub attachments: Option<Vec<attachment::Attachment>>,
pub fields: Option<Vec<field::Field>>,
pub password_history: Option<Vec<password_history::PasswordHistory>>,

pub creation_date: DateTime<Utc>,
pub deleted_date: Option<DateTime<Utc>>,
Expand Down Expand Up @@ -93,9 +93,9 @@ pub struct CipherView {
pub view_password: bool,
pub local_data: Option<LocalDataView>,

pub attachments: Vec<attachment::AttachmentView>,
pub fields: Vec<field::FieldView>,
pub password_history: Vec<password_history::PasswordHistoryView>,
pub attachments: Option<Vec<attachment::AttachmentView>>,
pub fields: Option<Vec<field::FieldView>>,
pub password_history: Option<Vec<password_history::PasswordHistoryView>>,

pub creation_date: DateTime<Utc>,
pub deleted_date: Option<DateTime<Utc>>,
Expand Down Expand Up @@ -202,7 +202,7 @@ impl Cipher {
let Some(login) = &self.login else {
return Ok(String::new());
};
login.username.decrypt(enc, org_id).unwrap_or_default()
login.username.decrypt(enc, org_id)?.unwrap_or_default()
}
CipherType::SecureNote => String::new(),
CipherType::Card => {
Expand Down Expand Up @@ -273,7 +273,11 @@ impl Decryptable<CipherListView> for Cipher {
reprompt: self.reprompt,
edit: self.edit,
view_password: self.view_password,
attachments: self.attachments.len() as u32,
attachments: self
.attachments
.as_ref()
.map(|a| a.len() as u32)
.unwrap_or(0),
creation_date: self.creation_date,
deleted_date: self.deleted_date,
revision_date: self.revision_date,
Expand Down
8 changes: 4 additions & 4 deletions crates/bitwarden/src/vault/cipher/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub enum FieldType {
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Field {
name: EncString,
value: EncString,
name: Option<EncString>,
value: Option<EncString>,
r#type: FieldType,

linked_id: Option<LinkedIdType>,
Expand All @@ -35,8 +35,8 @@ pub struct Field {
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct FieldView {
name: String,
value: String,
name: Option<String>,
value: Option<String>,
r#type: FieldType,

linked_id: Option<LinkedIdType>,
Expand Down
16 changes: 8 additions & 8 deletions crates/bitwarden/src/vault/cipher/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ pub enum UriMatchType {
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct LoginUri {
pub uri: EncString,
pub uri: Option<EncString>,
pub r#match: Option<UriMatchType>,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct LoginUriView {
pub uri: String,
pub uri: Option<String>,
pub r#match: Option<UriMatchType>,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Login {
pub username: EncString,
pub password: EncString,
pub username: Option<EncString>,
pub password: Option<EncString>,
pub password_revision_date: Option<DateTime<Utc>>,

pub uris: Vec<LoginUri>,
pub uris: Option<Vec<LoginUri>>,
pub totp: Option<EncString>,
pub autofill_on_page_load: Option<bool>,
}
Expand All @@ -56,11 +56,11 @@ pub struct Login {
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct LoginView {
pub username: String,
pub password: String,
pub username: Option<String>,
pub password: Option<String>,
pub password_revision_date: Option<DateTime<Utc>>,

pub uris: Vec<LoginUriView>,
pub uris: Option<Vec<LoginUriView>>,
pub totp: Option<String>,
pub autofill_on_page_load: Option<bool>,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden/src/vault/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ pub struct SendFileView {
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct SendText {
pub text: EncString,
pub text: Option<EncString>,
pub hidden: bool,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct SendTextView {
pub text: String,
pub text: Option<String>,
pub hidden: bool,
}

Expand Down