This repository was archived by the owner on Mar 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
WIP: Add ktx library module #74
Draft
mdocevski-infinum
wants to merge
7
commits into
master
Choose a base branch
from
feature/kotlin-flow-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0fbf2f
Add ktx library module
mdocevski 27d247b
Remove suspend modifier from GoldfingerKtx methods returning Flows
2c1bf90
Remove context as field from GoldfingerKtx.Builder
dfa966f
Limit Goldfinger Flows' capacity to single item
9ce5217
Update coroutines to 1.5.0
052bcbc
Update kotlin to 1.5.10
bc293f4
Replace Channel::offer with trySend in GoldfingerKtxCallback onResult
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| /build |
This file contains hidden or 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,51 @@ | ||
| apply plugin: 'maven-publish' | ||
| apply plugin: 'com.jfrog.bintray' | ||
|
|
||
| publishing { | ||
| publications { | ||
| Publication(MavenPublication) { | ||
| artifact("$buildDir/outputs/aar/ktx-release.aar") | ||
| groupId 'co.infinum' | ||
| artifact sourcesJar | ||
| artifact javadocsJar | ||
| artifactId 'goldfinger-ktx' | ||
| version versions.goldfinger | ||
|
|
||
| pom.withXml { | ||
| def root = asNode() | ||
| def dependenciesNode = root.appendNode('dependencies') | ||
|
|
||
| configurations.implementation.allDependencies.each { | ||
| def dependencyNode = dependenciesNode.appendNode('dependency') | ||
| if (it.name == 'core') { | ||
| dependencyNode.appendNode('groupId', 'co.infinum') | ||
| dependencyNode.appendNode('artifactId', 'goldfinger') | ||
| dependencyNode.appendNode('version', versions.goldfinger) | ||
| } else { | ||
| dependencyNode.appendNode('groupId', it.group) | ||
| dependencyNode.appendNode('artifactId', it.name) | ||
| dependencyNode.appendNode('version', it.version) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bintray { | ||
| user = System.getenv('BINTRAY_USER') | ||
| key = System.getenv('BINTRAY_API_KEY') | ||
| publish = false | ||
| publications = ['Publication'] | ||
|
|
||
| pkg { | ||
| repo = 'android' | ||
| name = 'goldfinger-ktx' | ||
| userOrg = 'infinum' | ||
| publicDownloadNumbers = true | ||
|
|
||
| version { | ||
| name = versions.goldfinger | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,24 @@ | ||
| apply plugin: 'com.android.library' | ||
|
|
||
| android { | ||
| compileSdkVersion sdk.target | ||
|
|
||
| defaultConfig { | ||
| minSdkVersion sdk.min | ||
| targetSdkVersion sdk.target | ||
| versionName versions.goldfinger | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation project(':core') | ||
| implementation "androidx.appcompat:appcompat:${versions.appcompat}" | ||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}" | ||
| implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.coroutines}" | ||
|
|
||
| testImplementation "junit:junit:${versions.junit}" | ||
| testImplementation "org.mockito:mockito-core:${versions.mockito}" | ||
| } | ||
|
|
||
| apply from: '../tasks.gradle' | ||
| apply from: 'bintray.gradle' |
This file contains hidden or 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,7 @@ | ||
| <manifest | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="co.infinum.goldfinger.ktx"> | ||
|
|
||
| <uses-permission android:name="android.permission.USE_BIOMETRIC"/> | ||
|
|
||
| </manifest> |
75 changes: 75 additions & 0 deletions
75
ktx/src/main/java/co/infinum/goldfinger/ktx/GoldfingerKtx.kt
This file contains hidden or 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,75 @@ | ||
| package co.infinum.goldfinger.ktx | ||
|
|
||
| import android.content.Context | ||
| import co.infinum.goldfinger.Goldfinger | ||
| import co.infinum.goldfinger.Goldfinger.PromptParams | ||
| import co.infinum.goldfinger.crypto.CipherCrypter | ||
| import co.infinum.goldfinger.crypto.CipherFactory | ||
| import co.infinum.goldfinger.crypto.MacCrypter | ||
| import co.infinum.goldfinger.crypto.MacFactory | ||
| import co.infinum.goldfinger.crypto.SignatureCrypter | ||
| import co.infinum.goldfinger.crypto.SignatureFactory | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface GoldfingerKtx { | ||
|
|
||
| fun hasFingerprintHardware(): Boolean | ||
|
|
||
| fun hasEnrolledFingerprint(): Boolean | ||
|
|
||
| fun canAuthenticate(): Boolean | ||
|
|
||
| suspend fun authenticate( | ||
| params: PromptParams, | ||
| ): Flow<Goldfinger.Result> | ||
|
|
||
| suspend fun encrypt( | ||
| params: PromptParams, | ||
| key: String, | ||
| value: String, | ||
| ): Flow<Goldfinger.Result> | ||
|
|
||
| suspend fun decrypt( | ||
| params: PromptParams, | ||
| key: String, | ||
| value: String, | ||
| ): Flow<Goldfinger.Result> | ||
|
|
||
| fun cancel() | ||
|
|
||
| class Builder(private val context: Context) { | ||
|
|
||
| private val baseBuilder: Goldfinger.Builder = Goldfinger.Builder(context) | ||
|
|
||
| fun build(): GoldfingerKtx = | ||
| GoldfingerKtxImpl(baseBuilder.build()) | ||
|
|
||
| fun cipherCrypter(cipherCrypter: CipherCrypter?): Builder = apply { | ||
| baseBuilder.cipherCrypter(cipherCrypter) | ||
| } | ||
|
|
||
| fun cipherFactory(cipherFactory: CipherFactory?): Builder = apply { | ||
| baseBuilder.cipherFactory(cipherFactory) | ||
| } | ||
|
|
||
| fun logEnabled(logEnabled: Boolean): Builder = apply { | ||
| baseBuilder.logEnabled(logEnabled) | ||
| } | ||
|
|
||
| fun macCrypter(macCrypter: MacCrypter?): Builder = apply { | ||
| baseBuilder.macCrypter(macCrypter) | ||
| } | ||
|
|
||
| fun macFactory(macFactory: MacFactory?): Builder = apply { | ||
| baseBuilder.macFactory(macFactory) | ||
| } | ||
|
|
||
| fun signatureCrypter(signatureCrypter: SignatureCrypter?): Builder = apply { | ||
| baseBuilder.signatureCrypter(signatureCrypter) | ||
| } | ||
|
|
||
| fun signatureFactory(signatureFactory: SignatureFactory?): Builder = apply { | ||
| baseBuilder.signatureFactory(signatureFactory) | ||
| } | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
ktx/src/main/java/co/infinum/goldfinger/ktx/GoldfingerKtxCallback.kt
This file contains hidden or 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,28 @@ | ||
| package co.infinum.goldfinger.ktx | ||
|
|
||
| import co.infinum.goldfinger.Goldfinger | ||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| import kotlinx.coroutines.channels.ProducerScope | ||
|
|
||
| @ExperimentalCoroutinesApi | ||
| class GoldfingerKtxCallback( | ||
| private val goldfinger: Goldfinger, | ||
| private val producerScope: ProducerScope<Goldfinger.Result>, | ||
| ) : Goldfinger.Callback { | ||
| override fun onResult(result: Goldfinger.Result) { | ||
| with(producerScope) { | ||
| if (!isClosedForSend) { | ||
| channel.offer(result) | ||
| if (result.type() == Goldfinger.Type.SUCCESS || result.type() == Goldfinger.Type.ERROR) { | ||
| channel.close() | ||
| } | ||
| } else { | ||
| goldfinger.cancel() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun onError(e: Exception) { | ||
| producerScope.channel.close(e) | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
ktx/src/main/java/co/infinum/goldfinger/ktx/GoldfingerKtxImpl.kt
This file contains hidden or 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,72 @@ | ||
| package co.infinum.goldfinger.ktx | ||
|
|
||
| import co.infinum.goldfinger.Goldfinger | ||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| import kotlinx.coroutines.channels.BufferOverflow | ||
| import kotlinx.coroutines.channels.awaitClose | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.buffer | ||
| import kotlinx.coroutines.flow.callbackFlow | ||
| import kotlinx.coroutines.flow.cancellable | ||
|
|
||
| @ExperimentalCoroutinesApi | ||
| class GoldfingerKtxImpl (private val goldfinger: Goldfinger) : GoldfingerKtx { | ||
|
|
||
| private fun inGoldfingerFlow(doWithCallback: (GoldfingerKtxCallback) -> Unit) = | ||
| callbackFlow { | ||
| doWithCallback( | ||
| GoldfingerKtxCallback( | ||
| goldfinger, | ||
| this, | ||
| ) | ||
| ) | ||
| awaitClose { goldfinger.cancel() } | ||
| } | ||
| .buffer( | ||
| onBufferOverflow = BufferOverflow.DROP_OLDEST, | ||
| ) | ||
| .cancellable() | ||
|
|
||
| override fun hasFingerprintHardware(): Boolean = goldfinger.hasFingerprintHardware() | ||
|
|
||
| override fun hasEnrolledFingerprint(): Boolean = goldfinger.hasEnrolledFingerprint() | ||
|
|
||
| override fun canAuthenticate(): Boolean = goldfinger.canAuthenticate() | ||
|
|
||
| override suspend fun authenticate(params: Goldfinger.PromptParams): Flow<Goldfinger.Result> = inGoldfingerFlow { callback -> | ||
| goldfinger.authenticate( | ||
| params, | ||
| callback, | ||
| ) | ||
| } | ||
|
|
||
| override suspend fun encrypt( | ||
| params: Goldfinger.PromptParams, | ||
| key: String, | ||
| value: String, | ||
| ): Flow<Goldfinger.Result> = inGoldfingerFlow { callback -> | ||
| goldfinger.encrypt( | ||
| params, | ||
| key, | ||
| value, | ||
| callback, | ||
| ) | ||
| } | ||
|
|
||
| override suspend fun decrypt( | ||
| params: Goldfinger.PromptParams, | ||
| key: String, | ||
| value: String, | ||
| ): Flow<Goldfinger.Result> = inGoldfingerFlow { callback -> | ||
| goldfinger.decrypt( | ||
| params, | ||
| key, | ||
| value, | ||
| callback, | ||
| ) | ||
| } | ||
|
|
||
| override fun cancel() { | ||
| goldfinger.cancel() | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| include ':core', ':example', ':rx' | ||
| include ':core', ':example', ':rx', ':ktx' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functions returning
Flowshould not be suspending, which you can do easily since in the implementationinGoldfingerFlowis not suspendingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, will correct