Skip to content

Commit

Permalink
Try to unlock the keyring collection
Browse files Browse the repository at this point in the history
  • Loading branch information
rainDiX authored and xou816 committed Feb 12, 2023
1 parent 653aec8 commit 59953e2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/app/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ impl Credentials {
pub fn retrieve() -> Result<Self, Error> {
let service = SecretService::new(EncryptionType::Dh)?;
let collection = service.get_default_collection()?;
if collection.is_locked()? {
collection.unlock()?;
}
let items = collection.search_items(make_attributes())?;
let item = items.get(0).ok_or(Error::NoResult)?.get_secret()?;
serde_json::from_slice(&item).map_err(|_| Error::Parse)
Expand All @@ -38,6 +41,9 @@ impl Credentials {
pub fn logout() -> Result<(), Error> {
let service = SecretService::new(EncryptionType::Dh)?;
let collection = service.get_default_collection()?;
if collection.is_locked()? {
collection.unlock()?;
}
let result = collection.search_items(make_attributes())?;
let item = result.get(0).ok_or(Error::NoResult)?;
item.delete()
Expand All @@ -46,6 +52,9 @@ impl Credentials {
pub fn save(&self) -> Result<(), Error> {
let service = SecretService::new(EncryptionType::Dh)?;
let collection = service.get_default_collection()?;
if collection.is_locked()? {
collection.unlock()?;
}
let encoded = serde_json::to_vec(&self).unwrap();
collection.create_item(
"Spotify Credentials",
Expand Down

0 comments on commit 59953e2

Please sign in to comment.