-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from infinum/dev
Release v1.0.0
- Loading branch information
Showing
14 changed files
with
207 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
lib/src/main/java/co/infinum/goldfinger/AsyncCryptoFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package co.infinum.goldfinger; | ||
|
||
import android.support.annotation.Nullable; | ||
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.Future; | ||
|
||
class AsyncCryptoFactory { | ||
|
||
private final CryptoFactory cryptoFactory; | ||
private final ExecutorService executor; | ||
private Future task; | ||
|
||
AsyncCryptoFactory(CryptoFactory cryptoFactory) { | ||
this.cryptoFactory = cryptoFactory; | ||
this.executor = Executors.newSingleThreadExecutor(); | ||
} | ||
|
||
void createCryptoObject(String keyName, Mode mode, AsyncCryptoFactory.Callback callback) { | ||
if (task != null && !task.isDone()) { | ||
task.cancel(true); | ||
} | ||
|
||
this.task = executor.submit(new CryptoObjectInitRunnable(cryptoFactory, keyName, mode, callback)); | ||
} | ||
|
||
static abstract class Callback { | ||
|
||
boolean canceled = false; | ||
|
||
abstract void onCryptoObjectCreated(@Nullable FingerprintManagerCompat.CryptoObject cryptoObject); | ||
|
||
void cancel() { | ||
canceled = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package co.infinum.goldfinger; | ||
|
||
/** | ||
* Singleton class that wraps time functions. | ||
* It is mainly needed for tests. | ||
*/ | ||
class Clock { | ||
|
||
private static Clock INSTANCE; | ||
|
||
private Clock() { | ||
} | ||
|
||
static Clock instance() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new Clock(); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
long currentTimeMs() { | ||
return System.currentTimeMillis(); | ||
} | ||
|
||
boolean isBeforeNow(long timeMs) { | ||
return timeMs < currentTimeMs(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lib/src/main/java/co/infinum/goldfinger/CryptoObjectInitRunnable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package co.infinum.goldfinger; | ||
|
||
import android.support.v4.hardware.fingerprint.FingerprintManagerCompat; | ||
|
||
class CryptoObjectInitRunnable implements Runnable { | ||
|
||
private final CryptoFactory cryptoFactory; | ||
private final String keyName; | ||
private final Mode mode; | ||
private final AsyncCryptoFactory.Callback callback; | ||
|
||
CryptoObjectInitRunnable(CryptoFactory cryptoFactory, String keyName, Mode mode, AsyncCryptoFactory.Callback callback) { | ||
this.cryptoFactory = cryptoFactory; | ||
this.keyName = keyName; | ||
this.mode = mode; | ||
this.callback = callback; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
FingerprintManagerCompat.CryptoObject cryptoObject = null; | ||
switch (mode) { | ||
case AUTHENTICATION: | ||
cryptoObject = cryptoFactory.createAuthenticationCryptoObject(keyName); | ||
break; | ||
case DECRYPTION: | ||
cryptoObject = cryptoFactory.createDecryptionCryptoObject(keyName); | ||
break; | ||
case ENCRYPTION: | ||
cryptoObject = cryptoFactory.createEncryptionCryptoObject(keyName); | ||
break; | ||
} | ||
|
||
if (!callback.canceled) { | ||
callback.onCryptoObjectCreated(cryptoObject); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.