Skip to content

Commit b1bbf60

Browse files
committed
Remove expect
1 parent 0532353 commit b1bbf60

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

crates/bitwarden-exporters/src/cxf/import.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,25 @@ fn parse_item(value: Item) -> Vec<ImportingCipher> {
124124

125125
// SSH Key credentials
126126
if let Some(ssh) = grouped.ssh.first() {
127-
let (ssh_key, fields) = to_ssh(ssh);
128-
129-
output.push(ImportingCipher {
130-
folder_id: None, // TODO: Handle folders
131-
name: value.title.clone(),
132-
notes: None,
133-
r#type: CipherType::SshKey(Box::new(ssh_key)),
134-
favorite: false,
135-
reprompt: 0,
136-
fields: [fields, scope.map(to_fields).unwrap_or_default()].concat(),
137-
revision_date,
138-
creation_date,
139-
deleted_date: None,
140-
})
127+
match to_ssh(ssh) {
128+
Ok((ssh_key, fields)) => {
129+
output.push(ImportingCipher {
130+
folder_id: None, // TODO: Handle folders
131+
name: value.title.clone(),
132+
notes: None,
133+
r#type: CipherType::SshKey(Box::new(ssh_key)),
134+
favorite: false,
135+
reprompt: 0,
136+
fields: [fields, scope.map(to_fields).unwrap_or_default()].concat(),
137+
revision_date,
138+
creation_date,
139+
deleted_date: None,
140+
})
141+
}
142+
Err(_) => {
143+
// Include information about the failed items, or import as note?
144+
}
145+
}
141146
}
142147

143148
output

crates/bitwarden-exporters/src/cxf/ssh.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
use bitwarden_ssh::import::import_der_key;
1+
use bitwarden_ssh::{error::SshKeyImportError, import::import_der_key};
22
use bitwarden_vault::FieldType;
33
use credential_exchange_format::SshKeyCredential;
44

55
use crate::{cxf::editable_field::create_field, Field, SshKey};
66

7-
pub(super) fn to_ssh(credential: &SshKeyCredential) -> (SshKey, Vec<Field>) {
7+
/// Convert SSH key credentials to SshKey and custom fields
8+
pub(super) fn to_ssh(
9+
credential: &SshKeyCredential,
10+
) -> Result<(SshKey, Vec<Field>), SshKeyImportError> {
811
// Convert to OpenSSH format
912
let encoded_key: Vec<u8> = credential.private_key.as_ref().into();
10-
let encoded_key = import_der_key(&encoded_key).expect("valid SSH key format");
13+
let encoded_key = import_der_key(&encoded_key)?;
1114

1215
let ssh = SshKey {
1316
private_key: encoded_key.private_key,
@@ -39,7 +42,7 @@ pub(super) fn to_ssh(credential: &SshKeyCredential) -> (SshKey, Vec<Field>) {
3942
.flatten()
4043
.collect();
4144

42-
(ssh, fields)
45+
Ok((ssh, fields))
4346
}
4447

4548
#[cfg(test)]
@@ -67,7 +70,7 @@ mod tests {
6770
key_generation_source: Some("Generated using OpenSSH".to_owned().into()),
6871
};
6972

70-
let (ssh, fields) = to_ssh(&credential);
73+
let (ssh, fields) = to_ssh(&credential).unwrap();
7174

7275
assert_eq!(ssh.private_key, "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUxOQAAACDQiCIk4t4YPC6bOSb7CLzac/vC+ZudqhYqY00cxqr8zAAAAIilFVdupRVX\nbgAAAAtzc2gtZWQyNTUxOQAAACDQiCIk4t4YPC6bOSb7CLzac/vC+ZudqhYqY00cxqr8zA\nAAAEA/lPVWpGrjuBbL+G/856Qx3HWIO+FOvLImY51iz5+0NdCIIiTi3hg8Lps5JvsIvNpz\n+8L5m52qFipjTRzGqvzMAAAAAAECAwQF\n-----END OPENSSH PRIVATE KEY-----\n");
7376
assert_eq!(

0 commit comments

Comments
 (0)