@@ -82,7 +82,7 @@ class EThree
82
82
83
83
private val virgilCrypto = VirgilCrypto ()
84
84
private val cardManager: CardManager
85
- private val localKeyStorage : KeyManagerLocal
85
+ private val keyManagerLocal : KeyManagerLocal
86
86
private val keyManagerCloud: KeyManagerCloud
87
87
88
88
init {
@@ -92,7 +92,7 @@ class EThree
92
92
VirgilCardVerifier (cardCrypto, false , false ),
93
93
VirgilCardClient (VIRGIL_BASE_URL + VIRGIL_CARDS_SERVICE_PATH ))
94
94
}
95
- localKeyStorage = KeyManagerLocal (tokenProvider.getToken(NO_CONTEXT ).identity, context)
95
+ keyManagerLocal = KeyManagerLocal (tokenProvider.getToken(NO_CONTEXT ).identity, context)
96
96
keyManagerCloud = KeyManagerCloud (currentIdentity(), tokenProvider)
97
97
}
98
98
@@ -109,7 +109,7 @@ class EThree
109
109
throw RegistrationException (" Card with identity " +
110
110
" ${currentIdentity()} already exists" )
111
111
112
- if (localKeyStorage .exists())
112
+ if (keyManagerLocal .exists())
113
113
throw PrivateKeyExistsException (" You already have a Private Key on this " +
114
114
" device for identity: ${currentIdentity()} . " +
115
115
" Please, use \' cleanup()\' function first." )
@@ -119,7 +119,7 @@ class EThree
119
119
this .publicKey,
120
120
currentIdentity())
121
121
122
- localKeyStorage .store(this .privateKey.rawKey)
122
+ keyManagerLocal .store(this .privateKey.rawKey)
123
123
}
124
124
}
125
125
@@ -139,9 +139,15 @@ class EThree
139
139
fun cleanup () {
140
140
checkPrivateKeyOrThrow()
141
141
142
- localKeyStorage .delete()
142
+ keyManagerLocal .delete()
143
143
}
144
144
145
+ /* *
146
+ * Checks whether the private key is present in the local storage of current device.
147
+ * Returns *true* if the key is present in the local key storage otherwise *false*.
148
+ */
149
+ fun hasLocalPrivateKey () = keyManagerLocal.exists()
150
+
145
151
/* *
146
152
* Encrypts the user's private key using the user's [password] and backs up the encrypted
147
153
* private key to Virgil's cloud. This enables users to log in from other devices and have
@@ -164,7 +170,7 @@ class EThree
164
170
if (password.isBlank())
165
171
throw IllegalArgumentException (" \' password\' should not be empty" )
166
172
167
- with (localKeyStorage .load()) {
173
+ with (keyManagerLocal .load()) {
168
174
keyManagerCloud.store(password,
169
175
this .value,
170
176
this .meta)
@@ -222,7 +228,7 @@ class EThree
222
228
*/
223
229
fun restorePrivateKey (password : String ): Deferred <Unit > = GlobalScope .asyncWithCatch(
224
230
{
225
- if (localKeyStorage .exists())
231
+ if (keyManagerLocal .exists())
226
232
throw RestoreKeyException (" You already have a Private Key on this device" +
227
233
" for identity: ${currentIdentity()} . Please, use" +
228
234
" \' cleanup()\' function first." )
@@ -233,7 +239,7 @@ class EThree
233
239
234
240
val keyEntry = keyManagerCloud.retrieve(password)
235
241
236
- localKeyStorage .store(keyEntry.data)
242
+ keyManagerLocal .store(keyEntry.data)
237
243
} else {
238
244
throw RestoreKeyException (" There is no key backup with " +
239
245
" identity: ${currentIdentity()} " )
@@ -256,7 +262,7 @@ class EThree
256
262
* @throws CryptoException
257
263
*/
258
264
fun rotatePrivateKey (): Deferred <Unit > = GlobalScope .async {
259
- if (localKeyStorage .exists())
265
+ if (keyManagerLocal .exists())
260
266
throw PrivateKeyExistsException (" You already have a Private Key on this device" +
261
267
" for identity: ${currentIdentity()} . Please, use" +
262
268
" \' cleanup()\' function first." )
@@ -278,7 +284,7 @@ class EThree
278
284
this .first.identifier)
279
285
cardManager.publishCard(rawCard)
280
286
281
- localKeyStorage .store(this .second.privateKey.rawKey)
287
+ keyManagerLocal .store(this .second.privateKey.rawKey)
282
288
}
283
289
}
284
290
@@ -486,7 +492,7 @@ class EThree
486
492
* from [tokenProvider].
487
493
*/
488
494
private fun loadCurrentPrivateKey (): PrivateKey =
489
- localKeyStorage .load().let {
495
+ keyManagerLocal .load().let {
490
496
virgilCrypto.importPrivateKey(it.value)
491
497
}
492
498
@@ -507,7 +513,7 @@ class EThree
507
513
* [PrivateKeyNotFoundException] exception.
508
514
*/
509
515
private fun checkPrivateKeyOrThrow () {
510
- if (! localKeyStorage .exists())
516
+ if (! keyManagerLocal .exists())
511
517
throw PrivateKeyNotFoundException (" You have to get private key first. Use " +
512
518
" \' register\' or \' restorePrivateKey\' functions." )
513
519
}
0 commit comments