31
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
32
*/
33
33
34
- package com.virgilsecurity.android.ethree.kotlin.interaction
35
-
36
- import android.content.Context
37
- import com.virgilsecurity.android.common.data.Const
38
- import com.virgilsecurity.android.common.data.Const.NO_CONTEXT
39
- import com.virgilsecurity.android.common.data.Const.VIRGIL_BASE_URL
40
- import com.virgilsecurity.android.common.data.Const.VIRGIL_CARDS_SERVICE_PATH
41
- import com.virgilsecurity.android.common.data.local.KeyManagerLocal
42
- import com.virgilsecurity.android.common.data.model.LookupResult
43
- import com.virgilsecurity.android.common.data.remote.KeyManagerCloud
34
+ package com.virgilsecurity.android.common.interaction
35
+
36
+ import com.virgilsecurity.android.common.Const
37
+ import com.virgilsecurity.android.common.Const.NO_CONTEXT
38
+ import com.virgilsecurity.android.common.Const.VIRGIL_BASE_URL
39
+ import com.virgilsecurity.android.common.Const.VIRGIL_CARDS_SERVICE_PATH
44
40
import com.virgilsecurity.android.common.exceptions.*
45
- import com.virgilsecurity.android.ethree.build.VersionVirgilAgent
46
- import com.virgilsecurity.android.ethree.kotlin.callback.OnGetTokenCallback
47
- import com.virgilsecurity.android.ethree.kotlin. model.Completable
48
- import com.virgilsecurity.android.ethree.kotlin.model.Result
41
+ import com.virgilsecurity.android.common.model.Completable
42
+ import com.virgilsecurity.android.common.model.LookupResult
43
+ import com.virgilsecurity.android.common. model.Result
44
+ import com.virgilsecurity.keyknox.build.VersionVirgilAgent
49
45
import com.virgilsecurity.keyknox.exception.DecryptionFailedException
50
46
import com.virgilsecurity.keyknox.exception.EntryAlreadyExistsException
51
47
import com.virgilsecurity.pythia.brainkey.BrainKey
@@ -61,7 +57,6 @@ import com.virgilsecurity.sdk.crypto.VirgilCrypto
61
57
import com.virgilsecurity.sdk.crypto.VirgilPrivateKey
62
58
import com.virgilsecurity.sdk.crypto.VirgilPublicKey
63
59
import com.virgilsecurity.sdk.exception.EmptyArgumentException
64
- import com.virgilsecurity.sdk.jwt.Jwt
65
60
import com.virgilsecurity.sdk.jwt.accessProviders.CachingJwtProvider
66
61
import com.virgilsecurity.sdk.jwt.contract.AccessTokenProvider
67
62
import com.virgilsecurity.sdk.storage.DefaultKeyStorage
@@ -70,19 +65,20 @@ import java.io.InputStream
70
65
import java.io.OutputStream
71
66
72
67
/* *
73
- * [EThree ] class simplifies work with Virgil Services to easily implement End to End Encrypted
68
+ * [EThreeCore ] class simplifies work with Virgil Services to easily implement End to End Encrypted
74
69
* communication.
75
70
*/
76
- class EThree
71
+ abstract class EThreeCore
77
72
/* *
78
- * @constructor Initializing [CardManager] with provided in [EThree .initialize] callback
73
+ * @constructor Initializing [CardManager] with provided in [EThreeCore .initialize] callback
79
74
* [onGetTokenCallback] using [CachingJwtProvider] also initializing [DefaultKeyStorage] with
80
75
* default settings.
81
- */ private constructor (context: Context , private val tokenProvider: AccessTokenProvider ) {
76
+ */
77
+ constructor (private val tokenProvider: AccessTokenProvider ) {
82
78
83
79
private val virgilCrypto = VirgilCrypto ()
84
80
private val cardManager: CardManager
85
- private val keyManagerLocal: KeyManagerLocal
81
+ protected abstract val keyManagerLocal: KeyManagerLocal
86
82
private val keyManagerCloud: KeyManagerCloud
87
83
88
84
init {
@@ -94,38 +90,11 @@ class EThree
94
90
VirgilCardClient (VIRGIL_BASE_URL + VIRGIL_CARDS_SERVICE_PATH ,
95
91
httpClient))
96
92
}
97
- keyManagerLocal = KeyManagerLocal (tokenProvider.getToken(NO_CONTEXT ).identity, context)
98
- keyManagerCloud = KeyManagerCloud (currentIdentity(),
99
- tokenProvider,
100
- VersionVirgilAgent .VERSION )
101
- }
102
-
103
- companion object {
104
- /* *
105
- * Current method allows you to initialize EThree helper class. To do this you
106
- * should provide [onGetTokenCallback] that must return Json Web Token string
107
- * representation with identity of the user which will use this class.
108
- * In [onResultListener] you will receive instance of [EThree] class or an [Throwable]
109
- * if something went wrong.
110
- *
111
- * To start execution of the current function, please see [Result] description.
112
- */
113
- @JvmStatic fun initialize (context : Context ,
114
- onGetTokenCallback : OnGetTokenCallback ) = object : Result <EThree > {
115
- override fun get (): EThree {
116
- val tokenProvider = CachingJwtProvider (CachingJwtProvider .RenewJwtCallback {
117
- Jwt (onGetTokenCallback.onGetToken())
118
- })
119
-
120
- // Just check whether we can get token, otherwise there's no reasons to
121
- // initialize EThree. We have caching JWT provider, so sequential calls
122
- // won't take much time, as token will be cached after first call.
123
- tokenProvider.getToken(NO_CONTEXT )
124
- return EThree (context, tokenProvider)
125
- }
126
- }
127
93
128
- private const val THROTTLE_TIMEOUT = 2 * 1000L // 2 seconds
94
+ keyManagerCloud = KeyManagerCloud (
95
+ currentIdentity(),
96
+ tokenProvider,
97
+ VersionVirgilAgent .VERSION )
129
98
}
130
99
131
100
/* *
@@ -157,7 +126,7 @@ class EThree
157
126
158
127
/* *
159
128
* Revokes the public key for current *identity* in Virgil's Cards Service. After this operation
160
- * you can call [EThree .register] again.
129
+ * you can call [EThreeCore .register] again.
161
130
*
162
131
* To start execution of the current function, please see [Completable] description.
163
132
*
@@ -606,7 +575,7 @@ class EThree
606
575
* [PublicKey] in [onResultListener] callback or [Throwable] if something went wrong.
607
576
*
608
577
* [PublicKeyNotFoundException] will be thrown for the first not found public key.
609
- * [EThree .register]
578
+ * [EThreeCore .register]
610
579
*
611
580
* Can be called only if private key is on the device, otherwise [PrivateKeyNotFoundException]
612
581
* exception will be thrown.
@@ -679,4 +648,8 @@ class EThree
679
648
" You have to get private key first. Use \' register\' " +
680
649
" or \' restorePrivateKey\' functions." )
681
650
}
651
+
652
+ companion object {
653
+ private const val THROTTLE_TIMEOUT = 2 * 1000L // 2 seconds
654
+ }
682
655
}
0 commit comments