blob: 3143d4d7e5d0f7b87c93b1d992cb7a0db7767e69 [file] [log] [blame]
Alex Klyubincc21bb32015-03-31 16:50:37 -07001/*
2 * Copyright (C) 2015 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
Alex Klyubind23a1f72015-03-27 14:39:28 -070017package android.security;
18
Alex Klyubinacc835f2015-03-31 15:26:56 -070019import android.security.keymaster.KeyCharacteristics;
Alex Klyubind23a1f72015-03-27 14:39:28 -070020
Alex Klyubinacc835f2015-03-31 15:26:56 -070021import java.util.ArrayList;
22import java.util.Date;
23import java.util.List;
24
Alex Klyubind23a1f72015-03-27 14:39:28 -070025/**
26 * @hide
27 */
28public abstract class KeymasterUtils {
29 private KeymasterUtils() {}
30
Alex Klyubinacc835f2015-03-31 15:26:56 -070031 public static Integer getInt(KeyCharacteristics keyCharacteristics, int tag) {
32 if (keyCharacteristics.hwEnforced.containsTag(tag)) {
33 return keyCharacteristics.hwEnforced.getInt(tag, -1);
34 } else if (keyCharacteristics.swEnforced.containsTag(tag)) {
35 return keyCharacteristics.swEnforced.getInt(tag, -1);
36 } else {
37 return null;
38 }
39 }
40
41 public static List<Integer> getInts(KeyCharacteristics keyCharacteristics, int tag) {
42 List<Integer> result = new ArrayList<Integer>();
43 result.addAll(keyCharacteristics.hwEnforced.getInts(tag));
44 result.addAll(keyCharacteristics.swEnforced.getInts(tag));
45 return result;
46 }
47
48 public static Date getDate(KeyCharacteristics keyCharacteristics, int tag) {
49 Date result = keyCharacteristics.hwEnforced.getDate(tag, null);
50 if (result == null) {
51 result = keyCharacteristics.swEnforced.getDate(tag, null);
52 }
53 return result;
54 }
55
56 public static boolean getBoolean(KeyCharacteristics keyCharacteristics, int tag) {
57 if (keyCharacteristics.hwEnforced.containsTag(tag)) {
58 return keyCharacteristics.hwEnforced.getBoolean(tag, false);
59 } else {
60 return keyCharacteristics.swEnforced.getBoolean(tag, false);
61 }
62 }
Alex Klyubind23a1f72015-03-27 14:39:28 -070063}