Skip to content

e3kit Android Java/Kotlin v0.5.0

Compare
Choose a tag to compare
@BuddahLD BuddahLD released this 10 Jun 15:18
· 139 commits to master since this release

Added:

  • Stream encryption;
  • Unregister;
  • Result and Completable;
  • 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. Stream encrypt doesn't sign encrypted data, and stream decrypt doesn't verify it. This is why stream decrypt doesn't need VirgilPublicKey unlike old data decrypt.
  • Unregister: this function is used to revoke the public key on Virgil Cloud service. You'll be able to call register with the same identity after a successful unregister. (You cannot call register twice with the same identity without unregister)
  • Result and Completable: 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 as RxJava, 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 the scope 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 call lookupPublicKeys(listOf(identity)) anymore, just use lookupPublicKeys(identity) instead.