Skip to content

Commit 5d7a03d

Browse files
Merge pull request #253 from kamou/move-items-and-secrets
Move items and secrets instead of cloning (#251)
2 parents 9d1b02f + ba9d576 commit 5d7a03d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/secret_service.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ impl CredentialApi for SsCredential {
159159
/// returns an [Ambiguous](ErrorCode::Ambiguous)
160160
/// error with a credential for each matching item.
161161
fn get_password(&self) -> Result<String> {
162-
let passwords: Vec<String> = self.map_matching_items(get_item_password, true)?;
163-
Ok(passwords[0].clone())
162+
Ok(self.map_matching_items(get_item_password, true)?.remove(0))
164163
}
165164

166165
/// Gets the secret on a unique matching item, if it exists.
@@ -171,8 +170,7 @@ impl CredentialApi for SsCredential {
171170
/// returns an [Ambiguous](ErrorCode::Ambiguous)
172171
/// error with a credential for each matching item.
173172
fn get_secret(&self) -> Result<Vec<u8>> {
174-
let secrets: Vec<Vec<u8>> = self.map_matching_items(get_item_secret, true)?;
175-
Ok(secrets[0].clone())
173+
Ok(self.map_matching_items(get_item_secret, true)?.remove(0))
176174
}
177175

178176
/// Get attributes on a unique matching item, if it exists
@@ -280,8 +278,9 @@ impl SsCredential {
280278
/// Construct a credential for this credential's underlying matching item,
281279
/// if there is exactly one.
282280
pub fn new_from_matching_item(&self) -> Result<Self> {
283-
let credentials = self.map_matching_items(Self::new_from_item, true)?;
284-
Ok(credentials[0].clone())
281+
Ok(self
282+
.map_matching_items(Self::new_from_item, true)?
283+
.remove(0))
285284
}
286285

287286
/// If there are multiple matching items for this credential, get all of their passwords.
@@ -324,8 +323,10 @@ impl SsCredential {
324323
let attributes: HashMap<&str, &str> = self.search_attributes(false).into_iter().collect();
325324
let search = ss.search_items(attributes).map_err(decode_error)?;
326325
let count = search.locked.len() + search.unlocked.len();
327-
if count == 0 && matches!(self.target.as_ref(), Some(t) if t == "default") {
328-
return self.map_matching_legacy_items(&ss, f, require_unique);
326+
if count == 0 {
327+
if let Some("default") = self.target.as_deref() {
328+
return self.map_matching_legacy_items(&ss, f, require_unique);
329+
}
329330
}
330331
if require_unique {
331332
if count == 0 {

0 commit comments

Comments
 (0)