From 5420faff34b8626fa65430b945c1bb098c26e40f Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 19 May 2023 18:58:48 +0530 Subject: [PATCH] feat(gpg): add methods to clear entries from GPG passphrase cache --- .../passwordstore/data/crypto/GPGPassphraseCache.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/app/passwordstore/data/crypto/GPGPassphraseCache.kt b/app/src/main/java/app/passwordstore/data/crypto/GPGPassphraseCache.kt index 193c363c..e00809a8 100644 --- a/app/src/main/java/app/passwordstore/data/crypto/GPGPassphraseCache.kt +++ b/app/src/main/java/app/passwordstore/data/crypto/GPGPassphraseCache.kt @@ -37,6 +37,19 @@ constructor( } } + suspend fun clearCachedPassphrase( + context: Context, + identifier: GpgIdentifier, + ) { + withContext(dispatcherProvider.io()) { + getPreferences(context).edit { remove(identifier.toString()) } + } + } + + suspend fun clearAllCachedPassphrases(context: Context) { + withContext(dispatcherProvider.io()) { getPreferences(context).edit { clear() } } + } + private suspend fun getPreferences(context: Context) = withContext(dispatcherProvider.io()) { EncryptedSharedPreferences.create(