• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 <keymasterV4_0/key_param_output.h>
18 
19 #include <keymasterV4_0/keymaster_tags.h>
20 
21 #include <iomanip>
22 
23 namespace android {
24 namespace hardware {
25 namespace keymaster {
26 
27 using ::std::ostream;
28 using ::std::endl;
29 
30 namespace V4_0 {
31 
operator <<(ostream & os,const hidl_vec<KeyParameter> & set)32 ostream& operator<<(ostream& os, const hidl_vec<KeyParameter>& set) {
33     if (set.size() == 0) {
34         os << "(Empty)" << endl;
35     } else {
36         os << "\n";
37         for (const auto& elem : set) os << elem << endl;
38     }
39     return os;
40 }
41 
operator <<(ostream & os,const KeyParameter & param)42 ostream& operator<<(ostream& os, const KeyParameter& param) {
43     os << param.tag << ": ";
44     switch (typeFromTag(param.tag)) {
45         case TagType::INVALID:
46             return os << " Invalid";
47         case TagType::UINT_REP:
48         case TagType::UINT:
49             return os << param.f.integer;
50         case TagType::ENUM_REP:
51         case TagType::ENUM:
52             switch (param.tag) {
53                 case Tag::ALGORITHM:
54                     return os << param.f.algorithm;
55                 case Tag::BLOCK_MODE:
56                     return os << param.f.blockMode;
57                 case Tag::PADDING:
58                     return os << param.f.paddingMode;
59                 case Tag::DIGEST:
60                     return os << param.f.digest;
61                 case Tag::EC_CURVE:
62                     return os << (int)param.f.ecCurve;
63                 case Tag::ORIGIN:
64                     return os << param.f.origin;
65                 case Tag::BLOB_USAGE_REQUIREMENTS:
66                     return os << (int)param.f.keyBlobUsageRequirements;
67                 case Tag::PURPOSE:
68                     return os << param.f.purpose;
69                 default:
70                     return os << " UNKNOWN ENUM " << param.f.integer;
71             }
72         case TagType::ULONG_REP:
73         case TagType::ULONG:
74             return os << param.f.longInteger;
75         case TagType::DATE:
76             return os << param.f.dateTime;
77         case TagType::BOOL:
78             return os << "true";
79         case TagType::BIGNUM:
80             os << " Bignum: ";
81             for (size_t i = 0; i < param.blob.size(); ++i) {
82                 os << std::hex << ::std::setw(2) << static_cast<int>(param.blob[i]) << ::std::dec;
83             }
84             return os;
85         case TagType::BYTES:
86             os << " Bytes: ";
87             for (size_t i = 0; i < param.blob.size(); ++i) {
88                 os << ::std::hex << ::std::setw(2) << static_cast<int>(param.blob[i]) << ::std::dec;
89             }
90             return os;
91     }
92     return os << "UNKNOWN TAG TYPE!";
93 }
94 
95 }  // namespace V4_0
96 }  // namespace keymaster
97 }  // namespace hardware
98 }  // namespace android
99