blob: 2eb2cefc361728b51fd14f2ea379e366ea181d8e [file] [log] [blame]
Alex Klyubinae6cb7a2015-06-22 18:09:35 -07001/*
Alex Klyubin8effa362015-06-24 16:06:55 -07002 * Copyright (C) 2015 The Android Open Source Project
Chad Brubaker45ff13e2015-01-21 14:00:55 -08003 *
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 *
Alex Klyubin8effa362015-06-24 16:06:55 -07008 * http://www.apache.org/licenses/LICENSE-2.0
Chad Brubaker45ff13e2015-01-21 14:00:55 -08009 *
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.security.keymaster;
18
Mathew Inwood4dbdcf42018-08-16 18:49:37 +010019import android.annotation.UnsupportedAppUsage;
Chad Brubaker45ff13e2015-01-21 14:00:55 -080020import android.os.Parcel;
21import android.os.Parcelable;
22
Alex Klyubinae6cb7a2015-06-22 18:09:35 -070023import java.math.BigInteger;
Alex Klyubin5927c9f2015-04-10 13:28:03 -070024import java.util.ArrayList;
25import java.util.Date;
Chad Brubaker45ff13e2015-01-21 14:00:55 -080026import java.util.List;
27
28/**
29 * @hide
30 */
31public class KeyCharacteristics implements Parcelable {
32 public KeymasterArguments swEnforced;
33 public KeymasterArguments hwEnforced;
34
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070035 public static final @android.annotation.NonNull Parcelable.Creator<KeyCharacteristics> CREATOR =
Alex Klyubinae6cb7a2015-06-22 18:09:35 -070036 new Parcelable.Creator<KeyCharacteristics>() {
Alex Klyubin5927c9f2015-04-10 13:28:03 -070037 @Override
Chad Brubaker45ff13e2015-01-21 14:00:55 -080038 public KeyCharacteristics createFromParcel(Parcel in) {
39 return new KeyCharacteristics(in);
40 }
41
Alex Klyubin5927c9f2015-04-10 13:28:03 -070042 @Override
Chad Brubaker45ff13e2015-01-21 14:00:55 -080043 public KeyCharacteristics[] newArray(int length) {
44 return new KeyCharacteristics[length];
45 }
46 };
47
Mathew Inwood4dbdcf42018-08-16 18:49:37 +010048 @UnsupportedAppUsage
Chad Brubaker45ff13e2015-01-21 14:00:55 -080049 public KeyCharacteristics() {}
50
51 protected KeyCharacteristics(Parcel in) {
52 readFromParcel(in);
53 }
54
Janis Danisevskisb0358e72018-11-02 10:34:07 -070055 /**
56 * Makes a shallow copy of other by copying the other's references to the KeymasterArguments
57 */
58 public void shallowCopyFrom(KeyCharacteristics other) {
59 this.swEnforced = other.swEnforced;
60 this.hwEnforced = other.hwEnforced;
61 }
62
Chad Brubaker45ff13e2015-01-21 14:00:55 -080063 @Override
64 public int describeContents() {
65 return 0;
66 }
67
Alex Klyubin5927c9f2015-04-10 13:28:03 -070068 @Override
Chad Brubaker45ff13e2015-01-21 14:00:55 -080069 public void writeToParcel(Parcel out, int flags) {
70 swEnforced.writeToParcel(out, flags);
71 hwEnforced.writeToParcel(out, flags);
72 }
73
Mathew Inwood4dbdcf42018-08-16 18:49:37 +010074 @UnsupportedAppUsage
Chad Brubaker45ff13e2015-01-21 14:00:55 -080075 public void readFromParcel(Parcel in) {
76 swEnforced = KeymasterArguments.CREATOR.createFromParcel(in);
77 hwEnforced = KeymasterArguments.CREATOR.createFromParcel(in);
78 }
Alex Klyubin5927c9f2015-04-10 13:28:03 -070079
Alex Klyubinae6cb7a2015-06-22 18:09:35 -070080 /**
81 * Returns the value of the specified enum tag or {@code defaultValue} if the tag is not
82 * present.
83 *
84 * @throws IllegalArgumentException if {@code tag} is not an enum tag.
85 */
86 public Integer getEnum(int tag) {
Alex Klyubin5927c9f2015-04-10 13:28:03 -070087 if (hwEnforced.containsTag(tag)) {
Alex Klyubinae6cb7a2015-06-22 18:09:35 -070088 return hwEnforced.getEnum(tag, -1);
Alex Klyubin5927c9f2015-04-10 13:28:03 -070089 } else if (swEnforced.containsTag(tag)) {
Alex Klyubinae6cb7a2015-06-22 18:09:35 -070090 return swEnforced.getEnum(tag, -1);
Alex Klyubin5927c9f2015-04-10 13:28:03 -070091 } else {
92 return null;
93 }
94 }
95
Alex Klyubinae6cb7a2015-06-22 18:09:35 -070096 /**
97 * Returns all values of the specified repeating enum tag.
98 *
99 * throws IllegalArgumentException if {@code tag} is not a repeating enum tag.
100 */
101 public List<Integer> getEnums(int tag) {
Alex Klyubin5927c9f2015-04-10 13:28:03 -0700102 List<Integer> result = new ArrayList<Integer>();
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700103 result.addAll(hwEnforced.getEnums(tag));
104 result.addAll(swEnforced.getEnums(tag));
Alex Klyubin5927c9f2015-04-10 13:28:03 -0700105 return result;
106 }
107
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700108 /**
109 * Returns the value of the specified unsigned 32-bit int tag or {@code defaultValue} if the tag
110 * is not present.
111 *
112 * @throws IllegalArgumentException if {@code tag} is not an unsigned 32-bit int tag.
113 */
114 public long getUnsignedInt(int tag, long defaultValue) {
Alex Klyubin708fc9402015-04-28 18:58:47 -0700115 if (hwEnforced.containsTag(tag)) {
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700116 return hwEnforced.getUnsignedInt(tag, defaultValue);
Alex Klyubin708fc9402015-04-28 18:58:47 -0700117 } else {
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700118 return swEnforced.getUnsignedInt(tag, defaultValue);
Alex Klyubin708fc9402015-04-28 18:58:47 -0700119 }
120 }
121
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700122 /**
123 * Returns all values of the specified repeating unsigned 64-bit long tag.
124 *
125 * @throws IllegalArgumentException if {@code tag} is not a repeating unsigned 64-bit long tag.
126 */
127 public List<BigInteger> getUnsignedLongs(int tag) {
128 List<BigInteger> result = new ArrayList<BigInteger>();
129 result.addAll(hwEnforced.getUnsignedLongs(tag));
130 result.addAll(swEnforced.getUnsignedLongs(tag));
Alex Klyubin708fc9402015-04-28 18:58:47 -0700131 return result;
132 }
133
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700134 /**
135 * Returns the value of the specified date tag or {@code null} if the tag is not present.
136 *
137 * @throws IllegalArgumentException if {@code tag} is not a date tag or if the tag's value
138 * represents a time instant which is after {@code 2^63 - 1} milliseconds since Unix
139 * epoch.
140 */
Alex Klyubin5927c9f2015-04-10 13:28:03 -0700141 public Date getDate(int tag) {
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700142 Date result = swEnforced.getDate(tag, null);
143 if (result != null) {
144 return result;
Alex Klyubin5927c9f2015-04-10 13:28:03 -0700145 }
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700146 return hwEnforced.getDate(tag, null);
Alex Klyubin5927c9f2015-04-10 13:28:03 -0700147 }
148
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700149 /**
150 * Returns {@code true} if the provided boolean tag is present, {@code false} if absent.
151 *
152 * @throws IllegalArgumentException if {@code tag} is not a boolean tag.
153 */
Alex Klyubin1eda77a2015-04-28 14:21:01 -0700154 public boolean getBoolean(int tag) {
155 if (hwEnforced.containsTag(tag)) {
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700156 return hwEnforced.getBoolean(tag);
Alex Klyubin5927c9f2015-04-10 13:28:03 -0700157 } else {
Alex Klyubinae6cb7a2015-06-22 18:09:35 -0700158 return swEnforced.getBoolean(tag);
Alex Klyubin5927c9f2015-04-10 13:28:03 -0700159 }
160 }
Chad Brubaker45ff13e2015-01-21 14:00:55 -0800161}
162