1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.biometrics; 18 19 import android.annotation.NonNull; 20 import android.security.keystore.AndroidKeyStoreProvider; 21 22 import java.security.Signature; 23 24 import javax.crypto.Cipher; 25 import javax.crypto.Mac; 26 27 /** 28 * A wrapper class for the crypto objects supported by BiometricPrompt and FingerprintManager. 29 * Currently the framework supports {@link Signature}, {@link Cipher} and {@link Mac} objects. 30 * @hide 31 */ 32 public class CryptoObject { 33 private final Object mCrypto; 34 CryptoObject(@onNull Signature signature)35 public CryptoObject(@NonNull Signature signature) { 36 mCrypto = signature; 37 } 38 CryptoObject(@onNull Cipher cipher)39 public CryptoObject(@NonNull Cipher cipher) { 40 mCrypto = cipher; 41 } 42 CryptoObject(@onNull Mac mac)43 public CryptoObject(@NonNull Mac mac) { 44 mCrypto = mac; 45 } 46 47 /** 48 * Get {@link Signature} object. 49 * @return {@link Signature} object or null if this doesn't contain one. 50 */ getSignature()51 public Signature getSignature() { 52 return mCrypto instanceof Signature ? (Signature) mCrypto : null; 53 } 54 55 /** 56 * Get {@link Cipher} object. 57 * @return {@link Cipher} object or null if this doesn't contain one. 58 */ getCipher()59 public Cipher getCipher() { 60 return mCrypto instanceof Cipher ? (Cipher) mCrypto : null; 61 } 62 63 /** 64 * Get {@link Mac} object. 65 * @return {@link Mac} object or null if this doesn't contain one. 66 */ getMac()67 public Mac getMac() { 68 return mCrypto instanceof Mac ? (Mac) mCrypto : null; 69 } 70 71 /** 72 * @hide 73 * @return the opId associated with this object or 0 if none 74 */ getOpId()75 public final long getOpId() { 76 return mCrypto != null 77 ? AndroidKeyStoreProvider.getKeyStoreOperationHandle(mCrypto) : 0; 78 } 79 }; 80