Mauin / RxFingerprint

Android Fingerprint authentication and encryption with RxJava
Apache License 2.0
379 stars 81 forks source link

Create RxFingerprint instance via Builder instead of static methods #72

Closed Mauin closed 6 years ago

Mauin commented 7 years ago

This is a proposal to move RxFingerprint away from it's static methods in the RxFingerprint class to access all RxFingerprint functions. Instead this proposal adds an RxFingerprint.Builder which would be used to create a concrete instance of RxFingerprint with all "constant" parameters defined per the instance. This results in easier and less duplicated methods for calling RxFingerprint encryption/decryption.

On the current master branch RxFingerprint has 5 methods with different parameters for encryption. This approach would simplify this and bring it down to 2 methods. This would make calling RxFingerprint clearer and would ensure that constant parameters are not changed across different calls to RxFingerprint.

Creating an RxFingerprint instance:

RxFingerprint rxFingerprint = new RxFingerprint.Builder(activity)
        .encryptionMethod(EncryptionMethod.RSA)
        .keyInvalidatedByBiometricEnrollment(true)
        .logger(new DefaultLogger())
        .build();

Encryption would then be simply calling:

Observable<FingerprintEncryptionResult> observable = rxFingerprint.encrypt(key, "Encrypt this, please")

Due to the breaking API changes this would result in a RxFingerprint v3.