Skip to content

Commit

Permalink
Implement function to remove a list of keyspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
micbakos-rdx committed Sep 5, 2024
1 parent c94fb6c commit ecad9ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ internal class AndroidStorageDriver(
private fun <T> Result<T>.reportSecureStorageReadFailure(
key: SecureStorageKey
) = onFailure { error ->
Timber.tag("Sargon").w(error,"Read")
throw when (error) {
is BiometricsFailure -> CommonException.SecureStorageAccessException(
key = key,
Expand All @@ -105,7 +104,6 @@ internal class AndroidStorageDriver(
private fun <T> Result<T>.reportSecureStorageWriteFailure(
key: SecureStorageKey
) = onFailure { error ->
Timber.tag("Sargon").w(error,"Write")
throw when (error) {
is BiometricsFailure -> CommonException.SecureStorageAccessException(
key = key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ sealed class KeySpec(val alias: String) {

internal abstract fun generateSecretKey(): Result<SecretKey>

open fun delete(): Result<Unit> = runCatching {
val keyStore = KeyStore.getInstance(PROVIDER).apply { load(null) }
keyStore.deleteEntry(alias)
}

internal fun getSecretKey(): Result<SecretKey?> = runCatching {
val keyStore = KeyStore.getInstance(PROVIDER).apply { load(null) }
(keyStore.getEntry(alias, null) as? KeyStore.SecretKeyEntry)?.secretKey
Expand All @@ -89,10 +84,6 @@ sealed class KeySpec(val alias: String) {
class RadixConnect(alias: String = KEY_ALIAS_RADIX_CONNECT): KeySpec(alias) {
override fun generateSecretKey(): Result<SecretKey> = AesKeyGeneratorBuilder(alias = alias)
.build()

override fun delete(): Result<Unit> = runCatching {
error("KeySpec for RadixConnect should not be deleted")
}
}

@KoverIgnore
Expand Down Expand Up @@ -194,5 +185,15 @@ sealed class KeySpec(val alias: String) {
private const val KEY_ALIAS_PROFILE = "EncryptedProfileAlias"
private const val KEY_ALIAS_MNEMONIC = "EncryptedMnemonicAlias"
private const val KEY_ALIAS_RADIX_CONNECT = "EncryptedRadixConnectSessionAlias"

/**
* Removes the given [keySpecs] from [KeyStore]
*/
fun remove(keySpecs: List<KeySpec>): Result<Unit> = runCatching {
val keyStore = KeyStore.getInstance(PROVIDER).apply { load(null) }
keySpecs.forEach {
keyStore.deleteEntry(it.alias)
}
}
}
}

0 comments on commit ecad9ba

Please sign in to comment.