| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.biometrics; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.security.identity.IdentityCredential; |
| 21 |
import android.security.identity.PresentationSession; |
| 22 |
import android.security.keystore2.AndroidKeyStoreProvider; |
| 23 |
|
| 24 |
import java.security.Signature; |
| 25 |
|
| 26 |
import javax.crypto.Cipher; |
| 27 |
import javax.crypto.Mac; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class CryptoObject { |
| 36 |
private final Object mCrypto; |
| 37 |
|
| 38 |
public CryptoObject(@NonNull Signature signature) { |
| 39 |
mCrypto = signature; |
| 40 |
} |
| 41 |
|
| 42 |
public CryptoObject(@NonNull Cipher cipher) { |
| 43 |
mCrypto = cipher; |
| 44 |
} |
| 45 |
|
| 46 |
public CryptoObject(@NonNull Mac mac) { |
| 47 |
mCrypto = mac; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
@Deprecated |
| 57 |
public CryptoObject(@NonNull IdentityCredential credential) { |
| 58 |
mCrypto = credential; |
| 59 |
} |
| 60 |
|
| 61 |
public CryptoObject(@NonNull PresentationSession session) { |
| 62 |
mCrypto = session; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public Signature getSignature() { |
| 70 |
return mCrypto instanceof Signature ? (Signature) mCrypto : null; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public Cipher getCipher() { |
| 78 |
return mCrypto instanceof Cipher ? (Cipher) mCrypto : null; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public Mac getMac() { |
| 86 |
return mCrypto instanceof Mac ? (Mac) mCrypto : null; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
@Deprecated |
| 95 |
public IdentityCredential getIdentityCredential() { |
| 96 |
return mCrypto instanceof IdentityCredential ? (IdentityCredential) mCrypto : null; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public PresentationSession getPresentationSession() { |
| 104 |
return mCrypto instanceof PresentationSession ? (PresentationSession) mCrypto : null; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public final long getOpId() { |
| 112 |
if (mCrypto == null) { |
| 113 |
return 0; |
| 114 |
} else if (mCrypto instanceof IdentityCredential) { |
| 115 |
return ((IdentityCredential) mCrypto).getCredstoreOperationHandle(); |
| 116 |
} else if (mCrypto instanceof PresentationSession) { |
| 117 |
return ((PresentationSession) mCrypto).getCredstoreOperationHandle(); |
| 118 |
} |
| 119 |
return AndroidKeyStoreProvider.getKeyStoreOperationHandle(mCrypto); |
| 120 |
} |
| 121 |
} |