Skip to content

Commit 0894b42

Browse files
committed
Move CipherEditRequest into CipherEditRequestInternal
1 parent 7a7acd5 commit 0894b42

File tree

1 file changed

+35
-38
lines changed
  • crates/bitwarden-vault/src/cipher/cipher_client

1 file changed

+35
-38
lines changed

crates/bitwarden-vault/src/cipher/cipher_client/edit.rs

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -104,34 +104,14 @@ impl TryFrom<CipherView> for CipherEditRequest {
104104
/// value. This allows us to calculate password history safely, without risking misuse.
105105
#[derive(Clone, Debug)]
106106
struct CipherEditRequestInternal {
107-
organization_id: Option<OrganizationId>,
108-
folder_id: Option<FolderId>,
109-
favorite: bool,
110-
reprompt: CipherRepromptType,
111-
name: String,
112-
notes: Option<String>,
113-
fields: Vec<FieldView>,
114-
r#type: CipherViewType,
115-
revision_date: DateTime<Utc>,
116-
archived_date: Option<DateTime<Utc>>,
107+
edit_request: CipherEditRequest,
117108
password_history: Vec<PasswordHistoryView>,
118-
key: Option<EncString>,
119109
}
120110

121111
impl CipherEditRequestInternal {
122-
fn new(req: CipherEditRequest, orig_cipher: &CipherView) -> Self {
112+
fn new(edit_request: CipherEditRequest, orig_cipher: &CipherView) -> Self {
123113
let mut internal_req = Self {
124-
organization_id: req.organization_id,
125-
folder_id: req.folder_id,
126-
favorite: req.favorite,
127-
reprompt: req.reprompt,
128-
name: req.name,
129-
notes: req.notes,
130-
fields: req.fields,
131-
r#type: req.r#type,
132-
revision_date: req.revision_date,
133-
archived_date: req.archived_date,
134-
key: req.key,
114+
edit_request,
135115
password_history: vec![],
136116
};
137117
internal_req.update_password_history(orig_cipher);
@@ -157,15 +137,15 @@ impl CipherEditRequestInternal {
157137
&mut self,
158138
original_cipher: &CipherView,
159139
) -> Vec<PasswordHistoryView> {
160-
if !matches!(self.r#type, CipherViewType::Login(_))
140+
if !matches!(self.edit_request.r#type, CipherViewType::Login(_))
161141
|| original_cipher.r#type != CipherType::Login
162142
{
163143
return vec![];
164144
}
165145

166146
let (Some(original_login), Some(current_login)) = (
167147
original_cipher.login.as_ref(),
168-
self.r#type.as_login_view_mut(),
148+
self.edit_request.r#type.as_login_view_mut(),
169149
) else {
170150
return vec![];
171151
};
@@ -196,7 +176,7 @@ impl CipherEditRequestInternal {
196176
) -> Vec<PasswordHistoryView> {
197177
let original_fields =
198178
Self::extract_hidden_fields(original_cipher.fields.as_deref().unwrap_or_default());
199-
let current_fields = Self::extract_hidden_fields(&self.fields);
179+
let current_fields = Self::extract_hidden_fields(&self.edit_request.fields);
200180

201181
original_fields
202182
.into_iter()
@@ -226,7 +206,7 @@ impl CipherEditRequestInternal {
226206
}
227207

228208
fn generate_checksums(&mut self) {
229-
if let Some(login) = &mut self.r#type.as_login_view_mut() {
209+
if let Some(login) = &mut self.edit_request.r#type.as_login_view_mut() {
230210
login.generate_checksums();
231211
}
232212
}
@@ -243,25 +223,34 @@ impl CompositeEncryptable<KeyIds, SymmetricKeyId, CipherRequestModel>
243223
let mut cipher_data = (*self).clone();
244224
cipher_data.generate_checksums();
245225

246-
let cipher_key = Cipher::decrypt_cipher_key(ctx, key, &self.key)?;
226+
let cipher_key = Cipher::decrypt_cipher_key(ctx, key, &self.edit_request.key)?;
247227

248228
let cipher_request = CipherRequestModel {
249229
encrypted_for: None,
250-
r#type: Some(cipher_data.r#type.get_cipher_type().into()),
251-
organization_id: cipher_data.organization_id.map(|id| id.to_string()),
252-
folder_id: cipher_data.folder_id.map(|id| id.to_string()),
253-
favorite: Some(cipher_data.favorite),
254-
reprompt: Some(cipher_data.reprompt.into()),
255-
key: cipher_data.key.map(|k| k.to_string()),
256-
name: cipher_data.name.encrypt(ctx, cipher_key)?.to_string(),
230+
r#type: Some(cipher_data.edit_request.r#type.get_cipher_type().into()),
231+
organization_id: cipher_data
232+
.edit_request
233+
.organization_id
234+
.map(|id| id.to_string()),
235+
folder_id: cipher_data.edit_request.folder_id.map(|id| id.to_string()),
236+
favorite: Some(cipher_data.edit_request.favorite),
237+
reprompt: Some(cipher_data.edit_request.reprompt.into()),
238+
key: cipher_data.edit_request.key.map(|k| k.to_string()),
239+
name: cipher_data
240+
.edit_request
241+
.name
242+
.encrypt(ctx, cipher_key)?
243+
.to_string(),
257244
notes: cipher_data
245+
.edit_request
258246
.notes
259247
.as_ref()
260248
.map(|n| n.encrypt(ctx, cipher_key))
261249
.transpose()?
262250
.map(|n| n.to_string()),
263251
fields: Some(
264252
cipher_data
253+
.edit_request
265254
.fields
266255
.encrypt_composite(ctx, cipher_key)?
267256
.into_iter()
@@ -279,39 +268,47 @@ impl CompositeEncryptable<KeyIds, SymmetricKeyId, CipherRequestModel>
279268
attachments: None,
280269
attachments2: None,
281270
login: cipher_data
271+
.edit_request
282272
.r#type
283273
.as_login_view()
284274
.map(|l| l.encrypt_composite(ctx, cipher_key))
285275
.transpose()?
286276
.map(|l| Box::new(l.into())),
287277
card: cipher_data
278+
.edit_request
288279
.r#type
289280
.as_card_view()
290281
.map(|c| c.encrypt_composite(ctx, cipher_key))
291282
.transpose()?
292283
.map(|c| Box::new(c.into())),
293284
identity: cipher_data
285+
.edit_request
294286
.r#type
295287
.as_identity_view()
296288
.map(|i| i.encrypt_composite(ctx, cipher_key))
297289
.transpose()?
298290
.map(|c| Box::new(c.into())),
299291

300292
secure_note: cipher_data
293+
.edit_request
301294
.r#type
302295
.as_secure_note_view()
303296
.map(|i| i.encrypt_composite(ctx, cipher_key))
304297
.transpose()?
305298
.map(|c| Box::new(c.into())),
306299
ssh_key: cipher_data
300+
.edit_request
307301
.r#type
308302
.as_ssh_key_view()
309303
.map(|i| i.encrypt_composite(ctx, cipher_key))
310304
.transpose()?
311305
.map(|c| Box::new(c.into())),
312306

313-
last_known_revision_date: Some(cipher_data.revision_date.to_rfc3339()),
314-
archived_date: cipher_data.archived_date.map(|d| d.to_rfc3339()),
307+
last_known_revision_date: Some(cipher_data.edit_request.revision_date.to_rfc3339()),
308+
archived_date: cipher_data
309+
.edit_request
310+
.archived_date
311+
.map(|d| d.to_rfc3339()),
315312
data: None,
316313
};
317314

@@ -321,7 +318,7 @@ impl CompositeEncryptable<KeyIds, SymmetricKeyId, CipherRequestModel>
321318

322319
impl IdentifyKey<SymmetricKeyId> for CipherEditRequestInternal {
323320
fn key_identifier(&self) -> SymmetricKeyId {
324-
match self.organization_id {
321+
match self.edit_request.organization_id {
325322
Some(organization_id) => SymmetricKeyId::Organization(organization_id),
326323
None => SymmetricKeyId::User,
327324
}

0 commit comments

Comments
 (0)