1 /*
2 * Copyright (C) 2016 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 "key_param_output.h"
18
19 #include <iomanip>
20
21 namespace android {
22 namespace hardware {
23
24 namespace keymaster {
25 namespace V3_0 {
26
operator <<(::std::ostream & os,const hidl_vec<KeyParameter> & set)27 ::std::ostream& operator<<(::std::ostream& os, const hidl_vec<KeyParameter>& set) {
28 if (set.size() == 0) {
29 os << "(Empty)" << ::std::endl;
30 } else {
31 os << "\n";
32 for (size_t i = 0; i < set.size(); ++i)
33 os << set[i] << ::std::endl;
34 }
35 return os;
36 }
37
operator <<(::std::ostream & os,ErrorCode value)38 ::std::ostream& operator<<(::std::ostream& os, ErrorCode value) {
39 return os << (int)value;
40 }
41
operator <<(::std::ostream & os,Digest value)42 ::std::ostream& operator<<(::std::ostream& os, Digest value) {
43 return os << stringify(value);
44 }
45
operator <<(::std::ostream & os,Algorithm value)46 ::std::ostream& operator<<(::std::ostream& os, Algorithm value) {
47 return os << stringify(value);
48 }
49
operator <<(::std::ostream & os,BlockMode value)50 ::std::ostream& operator<<(::std::ostream& os, BlockMode value) {
51 return os << stringify(value);
52 }
53
operator <<(::std::ostream & os,PaddingMode value)54 ::std::ostream& operator<<(::std::ostream& os, PaddingMode value) {
55 return os << stringify(value);
56 }
57
operator <<(::std::ostream & os,KeyOrigin value)58 ::std::ostream& operator<<(::std::ostream& os, KeyOrigin value) {
59 return os << stringify(value);
60 }
61
operator <<(::std::ostream & os,KeyPurpose value)62 ::std::ostream& operator<<(::std::ostream& os, KeyPurpose value) {
63 return os << stringify(value);
64 }
65
operator <<(::std::ostream & os,EcCurve value)66 ::std::ostream& operator<<(::std::ostream& os, EcCurve value) {
67 return os << stringify(value);
68 }
69
operator <<(::std::ostream & os,const KeyParameter & param)70 ::std::ostream& operator<<(::std::ostream& os, const KeyParameter& param) {
71 os << stringifyTag(param.tag) << ": ";
72 switch (typeFromTag(param.tag)) {
73 case TagType::INVALID:
74 return os << " Invalid";
75 case TagType::UINT_REP:
76 case TagType::UINT:
77 return os << param.f.integer;
78 case TagType::ENUM_REP:
79 case TagType::ENUM:
80 switch (param.tag) {
81 case Tag::ALGORITHM:
82 return os << param.f.algorithm;
83 case Tag::BLOCK_MODE:
84 return os << param.f.blockMode;
85 case Tag::PADDING:
86 return os << param.f.paddingMode;
87 case Tag::DIGEST:
88 return os << param.f.digest;
89 case Tag::EC_CURVE:
90 return os << (int)param.f.ecCurve;
91 case Tag::ORIGIN:
92 return os << param.f.origin;
93 case Tag::BLOB_USAGE_REQUIREMENTS:
94 return os << (int)param.f.keyBlobUsageRequirements;
95 case Tag::PURPOSE:
96 return os << param.f.purpose;
97 default:
98 return os << " UNKNOWN ENUM " << param.f.integer;
99 }
100 case TagType::ULONG_REP:
101 case TagType::ULONG:
102 return os << param.f.longInteger;
103 case TagType::DATE:
104 return os << param.f.dateTime;
105 case TagType::BOOL:
106 return os << "true";
107 case TagType::BIGNUM:
108 os << " Bignum: ";
109 for (size_t i = 0; i < param.blob.size(); ++i) {
110 os << ::std::hex << ::std::setw(2) << static_cast<int>(param.blob[i]) << ::std::dec;
111 }
112 return os;
113 case TagType::BYTES:
114 os << " Bytes: ";
115 for (size_t i = 0; i < param.blob.size(); ++i) {
116 os << ::std::hex << ::std::setw(2) << static_cast<int>(param.blob[i]) << ::std::dec;
117 }
118 return os;
119 }
120 return os << "UNKNOWN TAG TYPE!";
121 }
122
operator <<(::std::ostream & os,const KeyCharacteristics & chars)123 ::std::ostream& operator<<(::std::ostream& os, const KeyCharacteristics& chars) {
124 return os << "SW: " << chars.softwareEnforced << ::std::endl
125 << "TEE: " << chars.teeEnforced << ::std::endl;
126 }
127
128 } // namespace V3_0
129 } // namespace keymaster
130 } // namespace hardware
131 } // namespace android
132