blob: 74758ccfb18daaf029dab17c61d52baa25346368 [file] [log] [blame]
Shawn Willden5ada7b62014-07-29 09:44:17 -06001/*
2 * Copyright (C) 2014 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#include <stdlib.h>
18#include <string.h>
19#include <stddef.h>
20
21#include <assert.h>
22
Shawn Willden98d9b922014-08-26 08:14:10 -060023#include <keymaster/authorization_set.h>
24#include <keymaster/google_keymaster_utils.h>
Shawn Willden5ada7b62014-07-29 09:44:17 -060025
26namespace keymaster {
27
28static inline bool is_blob_tag(keymaster_tag_t tag) {
29 return (keymaster_tag_get_type(tag) == KM_BYTES || keymaster_tag_get_type(tag) == KM_BIGNUM);
30}
31
32const size_t STARTING_ELEMS_CAPACITY = 8;
33
Shawn Willden58e1a542014-08-08 21:58:29 -060034AuthorizationSet::AuthorizationSet(const AuthorizationSet& set)
Shawn Willden62de2662014-08-20 14:14:49 -060035 : Serializable(), elems_(NULL), indirect_data_(NULL) {
Shawn Willden76364712014-08-11 17:48:04 -060036 Reinitialize(set.elems_, set.elems_size_);
Shawn Willden5ada7b62014-07-29 09:44:17 -060037}
38
Shawn Willden8d336ae2014-08-09 15:47:05 -060039AuthorizationSet::~AuthorizationSet() {
40 FreeData();
41}
Shawn Willden58e1a542014-08-08 21:58:29 -060042
Shawn Willden37012132014-08-19 08:15:57 -060043bool AuthorizationSet::reserve_elems(size_t count) {
Shawn Willden437fbd12014-08-20 11:59:49 -060044 if (is_valid() != OK)
45 return false;
46
Shawn Willden37012132014-08-19 08:15:57 -060047 if (count >= elems_capacity_) {
48 keymaster_key_param_t* new_elems = new keymaster_key_param_t[count];
49 if (new_elems == NULL) {
50 set_invalid(ALLOCATION_FAILURE);
51 return false;
52 }
53 memcpy(new_elems, elems_, sizeof(*elems_) * elems_size_);
54 delete[] elems_;
55 elems_ = new_elems;
56 elems_capacity_ = count;
57 }
58 return true;
59}
60
61bool AuthorizationSet::reserve_indirect(size_t length) {
Shawn Willden437fbd12014-08-20 11:59:49 -060062 if (is_valid() != OK)
63 return false;
64
Shawn Willden37012132014-08-19 08:15:57 -060065 if (length > indirect_data_capacity_) {
66 uint8_t* new_data = new uint8_t[length];
67 if (new_data == NULL) {
68 set_invalid(ALLOCATION_FAILURE);
69 return false;
70 }
71 memcpy(new_data, indirect_data_, indirect_data_size_);
72
73 // Fix up the data pointers to point into the new region.
74 for (size_t i = 0; i < elems_size_; ++i) {
75 if (is_blob_tag(elems_[i].tag))
76 elems_[i].blob.data = new_data + (elems_[i].blob.data - indirect_data_);
77 }
78 delete[] indirect_data_;
79 indirect_data_ = new_data;
80 indirect_data_capacity_ = length;
81 }
82 return true;
83}
84
Shawn Willden5ada7b62014-07-29 09:44:17 -060085bool AuthorizationSet::Reinitialize(const keymaster_key_param_t* elems, const size_t count) {
86 FreeData();
87
Shawn Willden37012132014-08-19 08:15:57 -060088 if (!reserve_elems(count))
Shawn Willden5ada7b62014-07-29 09:44:17 -060089 return false;
Shawn Willden5ada7b62014-07-29 09:44:17 -060090
Shawn Willden37012132014-08-19 08:15:57 -060091 if (!reserve_indirect(ComputeIndirectDataSize(elems, count)))
92 return false;
93
94 memcpy(elems_, elems, sizeof(keymaster_key_param_t) * count);
95 elems_size_ = count;
Shawn Willden5ada7b62014-07-29 09:44:17 -060096 CopyIndirectData();
Shawn Willden37012132014-08-19 08:15:57 -060097 error_ = OK;
Shawn Willden5ada7b62014-07-29 09:44:17 -060098 return true;
99}
100
Shawn Willden5ada7b62014-07-29 09:44:17 -0600101void AuthorizationSet::set_invalid(Error error) {
Shawn Willden5ada7b62014-07-29 09:44:17 -0600102 FreeData();
Shawn Willden37012132014-08-19 08:15:57 -0600103 error_ = error;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600104}
105
106int AuthorizationSet::find(keymaster_tag_t tag, int begin) const {
Shawn Willden437fbd12014-08-20 11:59:49 -0600107 if (is_valid() != OK)
108 return -1;
109
Shawn Willden5ada7b62014-07-29 09:44:17 -0600110 int i = ++begin;
Shawn Willden8d336ae2014-08-09 15:47:05 -0600111 while (i < (int)elems_size_ && elems_[i].tag != tag)
112 ++i;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600113 if (i == (int)elems_size_)
114 return -1;
115 else
116 return i;
117}
118
119keymaster_key_param_t empty;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600120keymaster_key_param_t AuthorizationSet::operator[](int at) const {
Shawn Willden437fbd12014-08-20 11:59:49 -0600121 if (is_valid() == OK && at < (int)elems_size_) {
Shawn Willden8d336ae2014-08-09 15:47:05 -0600122 return elems_[at];
Shawn Willden5ada7b62014-07-29 09:44:17 -0600123 }
124 memset(&empty, 0, sizeof(empty));
125 return empty;
126}
127
Shawn Willden37012132014-08-19 08:15:57 -0600128bool AuthorizationSet::push_back(const AuthorizationSet& set) {
Shawn Willden437fbd12014-08-20 11:59:49 -0600129 if (is_valid() != OK)
130 return false;
131
Shawn Willden37012132014-08-19 08:15:57 -0600132 if (!reserve_elems(elems_size_ + set.elems_size_))
133 return false;
134
135 if (!reserve_indirect(indirect_data_size_ + set.indirect_data_size_))
136 return false;
137
138 for (size_t i = 0; i < set.size(); ++i)
139 if (!push_back(set[i]))
Shawn Willden5ada7b62014-07-29 09:44:17 -0600140 return false;
Shawn Willden37012132014-08-19 08:15:57 -0600141
142 return true;
143}
144
145bool AuthorizationSet::push_back(keymaster_key_param_t elem) {
Shawn Willden437fbd12014-08-20 11:59:49 -0600146 if (is_valid() != OK)
147 return false;
148
Shawn Willden37012132014-08-19 08:15:57 -0600149 if (elems_size_ >= elems_capacity_)
150 if (!reserve_elems(elems_capacity_ ? elems_capacity_ * 2 : STARTING_ELEMS_CAPACITY))
151 return false;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600152
153 if (is_blob_tag(elem.tag)) {
Shawn Willden37012132014-08-19 08:15:57 -0600154 if (indirect_data_capacity_ - indirect_data_size_ < elem.blob.data_length)
155 if (!reserve_indirect(2 * (indirect_data_capacity_ + elem.blob.data_length)))
Shawn Willden5ada7b62014-07-29 09:44:17 -0600156 return false;
Shawn Willden58e1a542014-08-08 21:58:29 -0600157
Shawn Willden5ada7b62014-07-29 09:44:17 -0600158 memcpy(indirect_data_ + indirect_data_size_, elem.blob.data, elem.blob.data_length);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600159 elem.blob.data = indirect_data_ + indirect_data_size_;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600160 indirect_data_size_ += elem.blob.data_length;
161 }
162
163 elems_[elems_size_++] = elem;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600164 return true;
165}
166
Shawn Willden8d336ae2014-08-09 15:47:05 -0600167static size_t serialized_size(const keymaster_key_param_t& param) {
168 switch (keymaster_tag_get_type(param.tag)) {
169 case KM_INVALID:
170 default:
171 return sizeof(uint32_t);
172 case KM_ENUM:
173 case KM_ENUM_REP:
174 case KM_INT:
175 case KM_INT_REP:
176 return sizeof(uint32_t) * 2;
177 case KM_LONG:
178 case KM_DATE:
179 return sizeof(uint32_t) + sizeof(uint64_t);
180 case KM_BOOL:
181 return sizeof(uint32_t) + 1;
182 break;
183 case KM_BIGNUM:
184 case KM_BYTES:
185 return sizeof(uint32_t) * 3;
186 }
Shawn Willden58e1a542014-08-08 21:58:29 -0600187}
188
Shawn Willden8d336ae2014-08-09 15:47:05 -0600189static uint8_t* serialize(const keymaster_key_param_t& param, uint8_t* buf, const uint8_t* end,
190 const uint8_t* indirect_base) {
Shawn Willden172f8c92014-08-17 07:50:34 -0600191 buf = append_uint32_to_buf(buf, end, param.tag);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600192 switch (keymaster_tag_get_type(param.tag)) {
193 case KM_INVALID:
194 break;
195 case KM_ENUM:
196 case KM_ENUM_REP:
Shawn Willden172f8c92014-08-17 07:50:34 -0600197 buf = append_uint32_to_buf(buf, end, param.enumerated);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600198 break;
199 case KM_INT:
200 case KM_INT_REP:
Shawn Willden172f8c92014-08-17 07:50:34 -0600201 buf = append_uint32_to_buf(buf, end, param.integer);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600202 break;
203 case KM_LONG:
Shawn Willden172f8c92014-08-17 07:50:34 -0600204 buf = append_uint64_to_buf(buf, end, param.long_integer);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600205 break;
206 case KM_DATE:
Shawn Willden172f8c92014-08-17 07:50:34 -0600207 buf = append_uint64_to_buf(buf, end, param.date_time);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600208 break;
209 case KM_BOOL:
210 if (buf < end)
211 *buf = static_cast<uint8_t>(param.boolean);
212 buf++;
213 break;
214 case KM_BIGNUM:
215 case KM_BYTES:
Shawn Willden172f8c92014-08-17 07:50:34 -0600216 buf = append_uint32_to_buf(buf, end, param.blob.data_length);
217 buf = append_uint32_to_buf(buf, end, param.blob.data - indirect_base);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600218 break;
219 }
220 return buf;
221}
222
Shawn Willden172f8c92014-08-17 07:50:34 -0600223static bool deserialize(keymaster_key_param_t* param, const uint8_t** buf_ptr, const uint8_t* end,
Shawn Willden8d336ae2014-08-09 15:47:05 -0600224 const uint8_t* indirect_base, const uint8_t* indirect_end) {
Shawn Willden172f8c92014-08-17 07:50:34 -0600225 if (!copy_uint32_from_buf(buf_ptr, end, &param->tag))
Shawn Willden8d336ae2014-08-09 15:47:05 -0600226 return false;
Shawn Willden8d336ae2014-08-09 15:47:05 -0600227
228 switch (keymaster_tag_get_type(param->tag)) {
229 default:
230 case KM_INVALID:
231 return false;
232 case KM_ENUM:
233 case KM_ENUM_REP:
Shawn Willden172f8c92014-08-17 07:50:34 -0600234 return copy_uint32_from_buf(buf_ptr, end, &param->enumerated);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600235 case KM_INT:
236 case KM_INT_REP:
Shawn Willden172f8c92014-08-17 07:50:34 -0600237 return copy_uint32_from_buf(buf_ptr, end, &param->integer);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600238 case KM_LONG:
Shawn Willden172f8c92014-08-17 07:50:34 -0600239 return copy_uint64_from_buf(buf_ptr, end, &param->long_integer);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600240 case KM_DATE:
Shawn Willden172f8c92014-08-17 07:50:34 -0600241 return copy_uint64_from_buf(buf_ptr, end, &param->date_time);
Shawn Willden8d336ae2014-08-09 15:47:05 -0600242 break;
243 case KM_BOOL:
Shawn Willden172f8c92014-08-17 07:50:34 -0600244 if (*buf_ptr < end) {
245 param->boolean = static_cast<bool>(**buf_ptr);
246 (*buf_ptr)++;
Shawn Willden8d336ae2014-08-09 15:47:05 -0600247 return true;
248 }
249 return false;
250
251 case KM_BIGNUM:
252 case KM_BYTES: {
Shawn Willden8d336ae2014-08-09 15:47:05 -0600253 uint32_t offset;
Shawn Willden172f8c92014-08-17 07:50:34 -0600254 if (!copy_uint32_from_buf(buf_ptr, end, &param->blob.data_length) ||
255 !copy_uint32_from_buf(buf_ptr, end, &offset))
Shawn Willden8d336ae2014-08-09 15:47:05 -0600256 return false;
257 if (static_cast<ptrdiff_t>(offset) > indirect_end - indirect_base ||
Shawn Willden172f8c92014-08-17 07:50:34 -0600258 static_cast<ptrdiff_t>(offset + param->blob.data_length) > indirect_end - indirect_base)
Shawn Willden8d336ae2014-08-09 15:47:05 -0600259 return false;
Shawn Willden8d336ae2014-08-09 15:47:05 -0600260 param->blob.data = indirect_base + offset;
261 return true;
262 }
263 }
264}
265
266size_t AuthorizationSet::SerializedSizeOfElements() const {
267 size_t size = 0;
268 for (size_t i = 0; i < elems_size_; ++i) {
269 size += serialized_size(elems_[i]);
270 }
271 return size;
272}
273
274size_t AuthorizationSet::SerializedSize() const {
275 return sizeof(uint32_t) + // Size of indirect_data_
276 indirect_data_size_ + // indirect_data_
277 sizeof(uint32_t) + // Number of elems_
278 sizeof(uint32_t) + // Size of elems_
279 SerializedSizeOfElements(); // elems_
280}
281
282uint8_t* AuthorizationSet::Serialize(uint8_t* buf, const uint8_t* end) const {
283 buf = append_size_and_data_to_buf(buf, end, indirect_data_, indirect_data_size_);
Shawn Willden172f8c92014-08-17 07:50:34 -0600284 buf = append_uint32_to_buf(buf, end, elems_size_);
285 buf = append_uint32_to_buf(buf, end, SerializedSizeOfElements());
Shawn Willden8d336ae2014-08-09 15:47:05 -0600286 for (size_t i = 0; i < elems_size_; ++i) {
287 buf = serialize(elems_[i], buf, end, indirect_data_);
288 }
289 return buf;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600290}
291
Shawn Willden37012132014-08-19 08:15:57 -0600292bool AuthorizationSet::DeserializeIndirectData(const uint8_t** buf_ptr, const uint8_t* end) {
Shawn Willdenf2282b32014-08-25 06:49:54 -0600293 UniquePtr<uint8_t[]> indirect_buf;
294 if (!copy_size_and_data_from_buf(buf_ptr, end, &indirect_data_size_, &indirect_buf)) {
Shawn Willden37012132014-08-19 08:15:57 -0600295 set_invalid(MALFORMED_DATA);
296 return false;
297 }
Shawn Willdenf2282b32014-08-25 06:49:54 -0600298 indirect_data_ = indirect_buf.release();
Shawn Willden37012132014-08-19 08:15:57 -0600299 return true;
300}
Shawn Willden5ada7b62014-07-29 09:44:17 -0600301
Shawn Willden37012132014-08-19 08:15:57 -0600302bool AuthorizationSet::DeserializeElementsData(const uint8_t** buf_ptr, const uint8_t* end) {
Shawn Willden8d336ae2014-08-09 15:47:05 -0600303 uint32_t elements_count;
304 uint32_t elements_size;
Shawn Willden37012132014-08-19 08:15:57 -0600305 if (!copy_uint32_from_buf(buf_ptr, end, &elements_count) ||
Shawn Willden172f8c92014-08-17 07:50:34 -0600306 !copy_uint32_from_buf(buf_ptr, end, &elements_size)) {
Shawn Willden58e1a542014-08-08 21:58:29 -0600307 set_invalid(MALFORMED_DATA);
Shawn Willden5ada7b62014-07-29 09:44:17 -0600308 return false;
309 }
310
Shawn Willden834e8072014-08-09 16:38:53 -0600311 // Note that the following validation of elements_count is weak, but it prevents allocation of
312 // elems_ arrays which are clearly too large to be reasonable.
Shawn Willden62de2662014-08-20 14:14:49 -0600313 if (static_cast<ptrdiff_t>(elements_size) > end - *buf_ptr ||
314 elements_count * sizeof(uint32_t) > elements_size) {
Shawn Willden834e8072014-08-09 16:38:53 -0600315 set_invalid(MALFORMED_DATA);
316 return false;
317 }
318
Shawn Willden37012132014-08-19 08:15:57 -0600319 if (!reserve_elems(elements_count))
Shawn Willden5ada7b62014-07-29 09:44:17 -0600320 return false;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600321
Shawn Willden8d336ae2014-08-09 15:47:05 -0600322 uint8_t* indirect_end = indirect_data_ + indirect_data_size_;
Shawn Willden172f8c92014-08-17 07:50:34 -0600323 const uint8_t* elements_end = *buf_ptr + elements_size;
Shawn Willden8d336ae2014-08-09 15:47:05 -0600324 for (size_t i = 0; i < elements_count; ++i) {
Shawn Willden172f8c92014-08-17 07:50:34 -0600325 if (!deserialize(elems_ + i, buf_ptr, elements_end, indirect_data_, indirect_end)) {
Shawn Willden8d336ae2014-08-09 15:47:05 -0600326 set_invalid(MALFORMED_DATA);
327 return false;
328 }
329 }
Shawn Willden37012132014-08-19 08:15:57 -0600330 elems_size_ = elements_count;
331 return true;
332}
Shawn Willden8d336ae2014-08-09 15:47:05 -0600333
Shawn Willden37012132014-08-19 08:15:57 -0600334bool AuthorizationSet::Deserialize(const uint8_t** buf_ptr, const uint8_t* end) {
335 FreeData();
336
337 if (!DeserializeIndirectData(buf_ptr, end) || !DeserializeElementsData(buf_ptr, end))
338 return false;
339
340 if (indirect_data_size_ != ComputeIndirectDataSize(elems_, elems_size_)) {
Shawn Willden58e1a542014-08-08 21:58:29 -0600341 set_invalid(MALFORMED_DATA);
Shawn Willden5ada7b62014-07-29 09:44:17 -0600342 return false;
Shawn Willden58e1a542014-08-08 21:58:29 -0600343 }
Shawn Willden8d336ae2014-08-09 15:47:05 -0600344 return true;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600345}
346
Shawn Willden941d1c42014-12-11 13:57:02 -0700347void AuthorizationSet::Clear() {
Shawn Willden1834d5f2014-12-08 12:41:59 -0700348 memset_s(elems_, 0, elems_size_ * sizeof(keymaster_key_param_t));
349 memset_s(indirect_data_, 0, indirect_data_size_);
Shawn Willden941d1c42014-12-11 13:57:02 -0700350 elems_size_ = 0;
351 indirect_data_size_ = 0;
352}
353
354void AuthorizationSet::FreeData() {
355 Clear();
Shawn Willden58e1a542014-08-08 21:58:29 -0600356
357 delete[] elems_;
358 delete[] indirect_data_;
359
Shawn Willden5ada7b62014-07-29 09:44:17 -0600360 elems_ = NULL;
361 indirect_data_ = NULL;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600362 elems_capacity_ = 0;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600363 indirect_data_capacity_ = 0;
Shawn Willden37012132014-08-19 08:15:57 -0600364 error_ = OK;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600365}
366
367/* static */
368size_t AuthorizationSet::ComputeIndirectDataSize(const keymaster_key_param_t* elems, size_t count) {
369 size_t size = 0;
370 for (size_t i = 0; i < count; ++i) {
371 if (is_blob_tag(elems[i].tag)) {
372 size += elems[i].blob.data_length;
373 }
374 }
375 return size;
376}
377
378void AuthorizationSet::CopyIndirectData() {
Shawn Willden37012132014-08-19 08:15:57 -0600379 memset_s(indirect_data_, 0, indirect_data_capacity_);
Shawn Willden5ada7b62014-07-29 09:44:17 -0600380
381 uint8_t* indirect_data_pos = indirect_data_;
382 for (size_t i = 0; i < elems_size_; ++i) {
Shawn Willden37012132014-08-19 08:15:57 -0600383 assert(indirect_data_pos <= indirect_data_ + indirect_data_capacity_);
Shawn Willden5ada7b62014-07-29 09:44:17 -0600384 if (is_blob_tag(elems_[i].tag)) {
385 memcpy(indirect_data_pos, elems_[i].blob.data, elems_[i].blob.data_length);
386 elems_[i].blob.data = indirect_data_pos;
387 indirect_data_pos += elems_[i].blob.data_length;
388 }
389 }
Shawn Willden37012132014-08-19 08:15:57 -0600390 assert(indirect_data_pos == indirect_data_ + indirect_data_capacity_);
391 indirect_data_size_ = indirect_data_pos - indirect_data_;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600392}
393
Shawn Willden5ada7b62014-07-29 09:44:17 -0600394bool AuthorizationSet::GetTagValueEnum(keymaster_tag_t tag, uint32_t* val) const {
395 int pos = find(tag);
396 if (pos == -1) {
397 return false;
398 }
Shawn Willdenebf627f2014-08-12 11:15:29 -0600399 *val = elems_[pos].enumerated;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600400 return true;
401}
402
403bool AuthorizationSet::GetTagValueEnumRep(keymaster_tag_t tag, size_t instance,
404 uint32_t* val) const {
405 size_t count = 0;
406 int pos = -1;
407 while (count <= instance) {
408 pos = find(tag, pos);
409 if (pos == -1) {
410 return false;
411 }
412 ++count;
413 }
Shawn Willdenebf627f2014-08-12 11:15:29 -0600414 *val = elems_[pos].enumerated;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600415 return true;
416}
417
418bool AuthorizationSet::GetTagValueInt(keymaster_tag_t tag, uint32_t* val) const {
419 int pos = find(tag);
420 if (pos == -1) {
421 return false;
422 }
Shawn Willdenebf627f2014-08-12 11:15:29 -0600423 *val = elems_[pos].integer;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600424 return true;
425}
426
427bool AuthorizationSet::GetTagValueIntRep(keymaster_tag_t tag, size_t instance,
428 uint32_t* val) const {
429 size_t count = 0;
430 int pos = -1;
431 while (count <= instance) {
432 pos = find(tag, pos);
433 if (pos == -1) {
434 return false;
435 }
436 ++count;
437 }
Shawn Willdenebf627f2014-08-12 11:15:29 -0600438 *val = elems_[pos].integer;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600439 return true;
440}
441
442bool AuthorizationSet::GetTagValueLong(keymaster_tag_t tag, uint64_t* val) const {
443 int pos = find(tag);
444 if (pos == -1) {
445 return false;
446 }
Shawn Willdenebf627f2014-08-12 11:15:29 -0600447 *val = elems_[pos].long_integer;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600448 return true;
449}
450
451bool AuthorizationSet::GetTagValueDate(keymaster_tag_t tag, uint64_t* val) const {
452 int pos = find(tag);
453 if (pos == -1) {
454 return false;
455 }
Shawn Willdenebf627f2014-08-12 11:15:29 -0600456 *val = elems_[pos].date_time;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600457 return true;
458}
459
460bool AuthorizationSet::GetTagValueBlob(keymaster_tag_t tag, keymaster_blob_t* val) const {
461 int pos = find(tag);
462 if (pos == -1) {
463 return false;
464 }
Shawn Willdenebf627f2014-08-12 11:15:29 -0600465 *val = elems_[pos].blob;
Shawn Willden5ada7b62014-07-29 09:44:17 -0600466 return true;
467}
468
469} // namespace keymaster