-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from AckeeCZ/feature/synchronized-keystore
🐛 Synchronize Android KeyStore operations
- Loading branch information
Showing
27 changed files
with
906 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../java/io/github/ackeecz/guardian/core/internal/AndroidKeysetManagerSynchronizedBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.github.ackeecz.guardian.core.internal | ||
|
||
import android.content.Context | ||
import com.google.crypto.tink.KeyTemplate | ||
import com.google.crypto.tink.integration.android.AndroidKeysetManager | ||
import kotlinx.coroutines.sync.Semaphore | ||
import kotlinx.coroutines.sync.withPermit | ||
|
||
/** | ||
* Decorator of [AndroidKeysetManager.Builder] that synchronizes Android KeyStore operations using | ||
* [semaphore]. | ||
*/ | ||
public class AndroidKeysetManagerSynchronizedBuilder(private val semaphore: Semaphore) { | ||
|
||
private val delegate = AndroidKeysetManager.Builder() | ||
|
||
public fun withKeyTemplate(template: KeyTemplate): AndroidKeysetManagerSynchronizedBuilder = apply { | ||
delegate.withKeyTemplate(template) | ||
} | ||
|
||
public fun withSharedPref( | ||
context: Context, | ||
keysetName: String, | ||
prefFileName: String, | ||
): AndroidKeysetManagerSynchronizedBuilder = apply { | ||
delegate.withSharedPref(context, keysetName, prefFileName) | ||
} | ||
|
||
public fun withMasterKeyUri(uri: String): AndroidKeysetManagerSynchronizedBuilder = apply { | ||
delegate.withMasterKeyUri(uri) | ||
} | ||
|
||
public suspend fun build(): AndroidKeysetManager { | ||
return semaphore.withPermit { delegate.build() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.