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

Try to unlock the keyring collection when it is locked #560

Merged
merged 1 commit into from
Feb 12, 2023
Merged
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
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