blob: 278348afa413587b97e48d9637293e2f6734a9ab [file] [log] [blame]
Janis Danisevskisc7a9fa22016-10-13 18:43:45 +01001/*
2**
3** Copyright 2016, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include <keystore/keymaster_tags.h>
19
20namespace keystore {
21
22template<typename TagList>
23struct TagStringifier;
24
25template<typename ... Tags>
26struct TagStringifier<MetaList<Tags...>> {
27 template<TagType tag_type, Tag tag>
28 static TypedTag<tag_type, tag> chooseString(TypedTag<tag_type, tag> ttag, Tag runtime_tag,
29 const char** result) {
30 if (tag == runtime_tag) {
31 *result = Tag2String<tag>::value();
32 }
33 return ttag;
34 }
35 static const char* stringify(Tag tag) {
36 const char* result = "unknown tag";
37 [] (Tags&&...) {}(chooseString(Tags(), tag, &result)...);
38 return result;
39 }
40};
41
42const char* stringifyTag(Tag tag) {
43 return TagStringifier<all_tags_t>::stringify(tag);
44}
45
46}