e3kit Android Java/Kotlin v0.5.0
Added:
- Stream encryption;
- Unregister;
Result
andCompletable
;- CoroutineScope control (usually for Kotlin);
- LookupResult typealias (for Kotlin only);
- lookupPublicKeys function overload with one
identity
;
Updated:
- lookupPublicKeys returns LookupResult;
- encrypt accepts LookupResult;
Fixed:
rotatePrivateKey
function;
Detailed info:
- Streams encryption: you can now encrypt streams. It's compatible with old
data
encryption, so you can encrypt/decrypt data->stream and vice versa. Streamencrypt
doesn't sign encrypted data, and streamdecrypt
doesn't verify it. This is why streamdecrypt
doesn't needVirgilPublicKey
unlike old datadecrypt
. - Unregister: this function is used to revoke the public key on Virgil Cloud service. You'll be able to call
register
with the sameidentity
after a successfulunregister
. (You cannot callregister
twice with the sameidentity
withoutunregister
) Result
andCompletable
: Now all async functions can be executed synchronously in the current thread or in a background thread with a callback. This gives you the ability to easily use e3kit with other libraries, such asRxJava
,RxKotlin
, and others.
Result
is used for functions that return some value. lookupPublicKeys
now returns Result. You can get the value from this Result type synchronously by calling get()
, or anynchronously via addCallback
. Sample code:
Sync:
val lookupResult = eThree.lookupPublicKeys(identity).get()
Async:
eThree.lookupPublicKeys(identity)
.addCallback(object : OnResultListener<LookupResult> {
override fun onSuccess(result: LookupResult) {
// Keys are here
}
override fun onError(throwable: Throwable) {
// Handle error
}
})
Completable
is used for functions that don't return any value. For example: register
. You can execute this function synchronously by calling execute()
, or anynchronously via addCallback
. Sample code:
Sync:
eThree.register().execute()
Async:
eThree.register().addCallback(object : OnCompleteListener {
override fun onSuccess() {
// Successfully registered
}
override fun onError(throwable: Throwable) {
// Handle error
}
})
Java usage will be similar to Kotlin.
To migrate from an older version of e3kit (< 0.5.0) to this new version with Result
and Completable
, you have to move callback from method arguments to the addCallback
method call.
- CoroutineScope control: it's possible to provide CoroutineScope in
addCallback
function as thescope
argument. It gives you the possibility to choose what thread you're using for async calls, cancel async requests, provide request lifetime, etc. You can read more about CoroutineScope here. It's common to use coroutines in Kotlin, but you can use it from Java as well. You can check out e3kit tests for basic usage of Java+CoroutineScope, but it's recommended to use Kotlin instead. - LookupResult typealias: It's an alias for Map<String, VirgilPublicKey> that can be used in Kotlin only. For Java nothing has changed - just use Map<String, VirgilPublicKey> as it was before.
- lookupPublicKeys function overload with one
identity
: there's no need to calllookupPublicKeys(listOf(identity))
anymore, just uselookupPublicKeys(identity)
instead.