Skip to content

Commit f413521

Browse files
authored
Merge pull request #26 from VirgilSecurity/sync-async
Added possibility to call methods sync or async
2 parents b5ee858 + 9845f82 commit f413521

File tree

22 files changed

+1695
-645
lines changed

22 files changed

+1695
-645
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ buildscript {
4141

4242
// Kotlin
4343
kotlin : '1.3.31',
44-
coroutines : '1.0.1',
44+
coroutines : '1.3.0-M1',
4545

4646
// Gradle
47-
gardle : '3.3.2',
47+
gardle : '3.4.1',
4848

4949
// Android
5050
android : '4.1.1.4',

ethree-common/src/main/java/com/virgilsecurity/android/common/data/remote/KeyManagerCloud.kt

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ import com.virgilsecurity.sdk.crypto.VirgilPrivateKey
4848
import com.virgilsecurity.sdk.crypto.VirgilPublicKey
4949
import com.virgilsecurity.sdk.jwt.contract.AccessTokenProvider
5050
import java.net.URL
51-
import kotlin.coroutines.resume
52-
import kotlin.coroutines.suspendCoroutine
5351

5452
/**
5553
* KeyManagerCloud
@@ -71,43 +69,38 @@ class KeyManagerCloud(
7169
.setPythiaCrypto(VirgilPythiaCrypto())
7270
.build()
7371

74-
suspend fun exists(password: String) = initCloudKeyStorage(password).exists(identity)
72+
fun exists(password: String) = initCloudKeyStorage(password).exists(identity)
7573

76-
suspend fun store(password: String, data: ByteArray, meta: Map<String, String>? = null) =
74+
fun store(password: String, data: ByteArray, meta: Map<String, String>? = null) =
7775
initCloudKeyStorage(password).store(identity, data, meta)
7876

79-
suspend fun retrieve(password: String) = initCloudKeyStorage(password).retrieve(identity)
77+
fun retrieve(password: String) = initCloudKeyStorage(password).retrieve(identity)
8078

81-
suspend fun delete(password: String) = initCloudKeyStorage(password).delete(identity)
79+
fun delete(password: String) = initCloudKeyStorage(password).delete(identity)
8280

83-
suspend fun deleteAll() =
84-
suspendCoroutine<Unit> {
85-
keyknoxClient.resetValue(tokenProvider.getToken(Const.NO_CONTEXT).stringRepresentation())
86-
it.resume(Unit)
87-
}
81+
fun deleteAll() =
82+
keyknoxClient.resetValue(tokenProvider.getToken(Const.NO_CONTEXT).stringRepresentation())
8883

89-
suspend fun updateRecipients(password: String,
90-
publicKeys: List<VirgilPublicKey>,
91-
privateKey: VirgilPrivateKey) =
84+
fun updateRecipients(password: String,
85+
publicKeys: List<VirgilPublicKey>,
86+
privateKey: VirgilPrivateKey) =
9287
initCloudKeyStorage(password).updateRecipients(publicKeys, privateKey)
9388

9489
/**
9590
* Initializes [SyncKeyStorage] with default settings, [tokenProvider] and provided
9691
* [password] after that returns initialized [SyncKeyStorage] object.
9792
*/
98-
private suspend fun initCloudKeyStorage(password: String): CloudKeyStorage =
99-
suspendCoroutine {
100-
BrainKey(brainKeyContext).generateKeyPair(password)
101-
.let { keyPair ->
102-
val keyknoxManager = KeyknoxManager(tokenProvider,
103-
keyknoxClient,
104-
listOf(keyPair.publicKey),
105-
keyPair.privateKey,
106-
KeyknoxCrypto())
107-
val cloudKeyStorage = CloudKeyStorage(keyknoxManager).also { cloudKeyStorage ->
108-
cloudKeyStorage.retrieveCloudEntries()
109-
}
110-
it.resume(cloudKeyStorage)
93+
private fun initCloudKeyStorage(password: String): CloudKeyStorage =
94+
BrainKey(brainKeyContext).generateKeyPair(password)
95+
.let { keyPair ->
96+
val keyknoxManager = KeyknoxManager(tokenProvider,
97+
keyknoxClient,
98+
listOf(keyPair.publicKey),
99+
keyPair.privateKey,
100+
KeyknoxCrypto())
101+
val cloudKeyStorage = CloudKeyStorage(keyknoxManager).also { cloudKeyStorage ->
102+
cloudKeyStorage.retrieveCloudEntries()
111103
}
112-
}
104+
cloudKeyStorage
105+
}
113106
}

ethree-common/src/main/java/com/virgilsecurity/android/common/exceptions/Exceptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ class PrivateKeyExistsException @JvmOverloads constructor(
8585
override val message: String? = null, throwable: Throwable? = null
8686
) : RuntimeException(message, throwable)
8787

88-
class UnregistrationException @JvmOverloads constructor(
88+
class UnRegistrationException @JvmOverloads constructor(
8989
override val message: String? = null, throwable: Throwable? = null
9090
) : RuntimeException(message, throwable)

ethree-kotlin-coroutines/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ dependencies {
8686
task generateVersionVirgilAgent {
8787
outputs.dir "$buildDir/generated"
8888
doFirst {
89-
def versionFile = file("$buildDir/generated/com/virgilsecurity/android/ethreecoroutines/build/VersionVirgilAgent.kt")
89+
def versionFile = file("$buildDir/generated/release/com/virgilsecurity/android/ethreecoroutines/build/VersionVirgilAgent.kt")
9090
versionFile.parentFile.mkdirs()
9191
versionFile.text =
9292
"""
@@ -99,7 +99,7 @@ object VersionVirgilAgent {
9999
}
100100
}
101101

102-
project.android.sourceSets.main.java.srcDirs = ["${buildDir}/generated/", "src/main/java"]
102+
project.android.sourceSets.main.java.srcDirs = ["${buildDir}/generated/release/", "src/main/java"]
103103

104104
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
105105
dependsOn(generateVersionVirgilAgent)

ethree-kotlin-coroutines/src/main/java/com/virgilsecurity/android/ethreecoroutines/interaction/EThree.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
package com.virgilsecurity.android.ethreecoroutines.interaction
3535

3636
import android.content.Context
37+
import com.virgilsecurity.android.common.data.Const.NO_CONTEXT
38+
import com.virgilsecurity.android.common.data.Const.VIRGIL_BASE_URL
39+
import com.virgilsecurity.android.common.data.Const.VIRGIL_CARDS_SERVICE_PATH
3740
import com.virgilsecurity.android.common.data.local.KeyManagerLocal
3841
import com.virgilsecurity.android.common.data.remote.KeyManagerCloud
3942
import com.virgilsecurity.android.common.exceptions.*
@@ -216,6 +219,7 @@ class EThree
216219

217220
keyManagerCloud.delete(password)
218221
}
222+
Unit
219223
},
220224
{
221225
if (it is DecryptionFailedException)

ethree-kotlin/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ android {
5555
}
5656

5757
group 'com.virgilsecurity'
58-
version '0.4.2'
58+
version '0.5.0'
5959

6060
dependencies {
6161
// Inner dependencies
@@ -86,7 +86,7 @@ dependencies {
8686
task generateVersionVirgilAgent {
8787
outputs.dir "$buildDir/generated"
8888
doFirst {
89-
def versionFile = file("$buildDir/generated/com/virgilsecurity/android/ethree/build/VersionVirgilAgent.kt")
89+
def versionFile = file("$buildDir/generated/release/com/virgilsecurity/android/ethree/build/VersionVirgilAgent.kt")
9090
versionFile.parentFile.mkdirs()
9191
versionFile.text =
9292
"""
@@ -99,7 +99,9 @@ object VersionVirgilAgent {
9999
}
100100
}
101101

102-
project.android.sourceSets.main.java.srcDirs = ["${buildDir}/generated/", "src/main/java"]
102+
103+
104+
project.android.sourceSets.main.java.srcDirs = ["${buildDir}/generated/release/", "src/main/java"]
103105

104106
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
105107
dependsOn(generateVersionVirgilAgent)
@@ -109,7 +111,7 @@ sourceCompatibility = "8"
109111
targetCompatibility = "8"
110112

111113
task sourcesJar(type: Jar) {
112-
from(project.android.sourceSets.main.java)
114+
from(project.android.sourceSets.main.java.srcDirs)
113115
classifier = 'sources'
114116
}
115117

ethree-kotlin/src/main/java/com/virgilsecurity/android/ethree/kotlin/callback/OnCompleteListener.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
/*
2+
* Copyright (c) 2015-2019, Virgil Security, Inc.
3+
*
4+
* Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
5+
*
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* (1) Redistributions of source code must retain the above copyright notice, this
12+
* list of conditions and the following disclaimer.
13+
*
14+
* (2) Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* (3) Neither the name of virgil nor the names of its
19+
* contributors may be used to endorse or promote products derived from
20+
* this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
134
package com.virgilsecurity.android.ethree.kotlin.callback
235

336
/**

0 commit comments

Comments
 (0)