blob: 787dc6696cd396201c0661168675acfc97d1c9cc [file] [log] [blame]
Kevin Chyn66682562018-01-25 18:26:46 -08001/*
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
17package android.hardware.biometrics;
18
19import android.annotation.NonNull;
20import android.security.keystore.AndroidKeyStoreProvider;
21
22import java.security.Signature;
23
24import javax.crypto.Cipher;
25import javax.crypto.Mac;
26
27/**
Kevin Chyn9374c9f2019-04-04 17:46:18 -070028 * 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.
Kevin Chyn66682562018-01-25 18:26:46 -080030 * @hide
31 */
32public class CryptoObject {
33 private final Object mCrypto;
34
35 public CryptoObject(@NonNull Signature signature) {
36 mCrypto = signature;
37 }
38
39 public CryptoObject(@NonNull Cipher cipher) {
40 mCrypto = cipher;
41 }
42
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 */
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 */
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 */
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 */
75 public final long getOpId() {
76 return mCrypto != null
77 ? AndroidKeyStoreProvider.getKeyStoreOperationHandle(mCrypto) : 0;
78 }
79};