Improve detection of configure PIN code.
This commit is contained in:
parent
2f45ca8835
commit
61374bca4e
13 changed files with 77 additions and 44 deletions
|
|
@ -16,4 +16,5 @@ android {
|
|||
|
||||
dependencies {
|
||||
api(projects.libraries.cryptography.api)
|
||||
implementation(libs.coroutines.core)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,20 +10,39 @@ package io.element.android.libraries.cryptography.test
|
|||
|
||||
import io.element.android.libraries.cryptography.api.AESEncryptionSpecs
|
||||
import io.element.android.libraries.cryptography.api.SecretKeyRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.SecretKey
|
||||
|
||||
class SimpleSecretKeyRepository : SecretKeyRepository {
|
||||
private var secretKeyForAlias = HashMap<String, SecretKey>()
|
||||
|
||||
override fun getOrCreateKey(alias: String, requiresUserAuthentication: Boolean): SecretKey {
|
||||
private val hasKeyMap = ConcurrentHashMap<String, MutableStateFlow<Boolean>>()
|
||||
|
||||
override fun hasKey(alias: String): Flow<Boolean> {
|
||||
return hasKeyMap.getOrPut(alias) {
|
||||
MutableStateFlow(false)
|
||||
}.asStateFlow()
|
||||
}
|
||||
|
||||
override suspend fun getOrCreateKey(alias: String, requiresUserAuthentication: Boolean): SecretKey {
|
||||
return secretKeyForAlias.getOrPut(alias) {
|
||||
generateKey()
|
||||
generateKey().also {
|
||||
hasKeyMap.getOrPut(alias) {
|
||||
MutableStateFlow(true)
|
||||
}.emit(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteKey(alias: String) {
|
||||
override suspend fun deleteKey(alias: String) {
|
||||
secretKeyForAlias.remove(alias)
|
||||
hasKeyMap.getOrPut(alias) {
|
||||
MutableStateFlow(false)
|
||||
}.emit(false)
|
||||
}
|
||||
|
||||
private fun generateKey(): SecretKey {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue