1 //
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
17 // THIS CODE IS GENERATED.
18
19 #include "attestation/common/print_common_proto.h"
20
21 #include <string>
22
23 #include <base/strings/string_number_conversions.h>
24 #include <base/strings/stringprintf.h>
25
26 namespace attestation {
27
GetProtoDebugString(KeyType value)28 std::string GetProtoDebugString(KeyType value) {
29 return GetProtoDebugStringWithIndent(value, 0);
30 }
31
GetProtoDebugStringWithIndent(KeyType value,int indent_size)32 std::string GetProtoDebugStringWithIndent(KeyType value, int indent_size) {
33 if (value == KEY_TYPE_RSA) {
34 return "KEY_TYPE_RSA";
35 }
36 if (value == KEY_TYPE_ECC) {
37 return "KEY_TYPE_ECC";
38 }
39 return "<unknown>";
40 }
41
GetProtoDebugString(KeyUsage value)42 std::string GetProtoDebugString(KeyUsage value) {
43 return GetProtoDebugStringWithIndent(value, 0);
44 }
45
GetProtoDebugStringWithIndent(KeyUsage value,int indent_size)46 std::string GetProtoDebugStringWithIndent(KeyUsage value, int indent_size) {
47 if (value == KEY_USAGE_SIGN) {
48 return "KEY_USAGE_SIGN";
49 }
50 if (value == KEY_USAGE_DECRYPT) {
51 return "KEY_USAGE_DECRYPT";
52 }
53 return "<unknown>";
54 }
55
GetProtoDebugString(CertificateProfile value)56 std::string GetProtoDebugString(CertificateProfile value) {
57 return GetProtoDebugStringWithIndent(value, 0);
58 }
59
GetProtoDebugStringWithIndent(CertificateProfile value,int indent_size)60 std::string GetProtoDebugStringWithIndent(CertificateProfile value,
61 int indent_size) {
62 if (value == ENTERPRISE_MACHINE_CERTIFICATE) {
63 return "ENTERPRISE_MACHINE_CERTIFICATE";
64 }
65 if (value == ENTERPRISE_USER_CERTIFICATE) {
66 return "ENTERPRISE_USER_CERTIFICATE";
67 }
68 if (value == CONTENT_PROTECTION_CERTIFICATE) {
69 return "CONTENT_PROTECTION_CERTIFICATE";
70 }
71 if (value == CONTENT_PROTECTION_CERTIFICATE_WITH_STABLE_ID) {
72 return "CONTENT_PROTECTION_CERTIFICATE_WITH_STABLE_ID";
73 }
74 if (value == CAST_CERTIFICATE) {
75 return "CAST_CERTIFICATE";
76 }
77 if (value == GFSC_CERTIFICATE) {
78 return "GFSC_CERTIFICATE";
79 }
80 return "<unknown>";
81 }
82
GetProtoDebugString(const Quote & value)83 std::string GetProtoDebugString(const Quote& value) {
84 return GetProtoDebugStringWithIndent(value, 0);
85 }
86
GetProtoDebugStringWithIndent(const Quote & value,int indent_size)87 std::string GetProtoDebugStringWithIndent(const Quote& value, int indent_size) {
88 std::string indent(indent_size, ' ');
89 std::string output =
90 base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
91
92 if (value.has_quote()) {
93 output += indent + " quote: ";
94 base::StringAppendF(
95 &output, "%s",
96 base::HexEncode(value.quote().data(), value.quote().size()).c_str());
97 output += "\n";
98 }
99 if (value.has_quoted_data()) {
100 output += indent + " quoted_data: ";
101 base::StringAppendF(
102 &output, "%s",
103 base::HexEncode(value.quoted_data().data(), value.quoted_data().size())
104 .c_str());
105 output += "\n";
106 }
107 if (value.has_quoted_pcr_value()) {
108 output += indent + " quoted_pcr_value: ";
109 base::StringAppendF(&output, "%s",
110 base::HexEncode(value.quoted_pcr_value().data(),
111 value.quoted_pcr_value().size())
112 .c_str());
113 output += "\n";
114 }
115 if (value.has_pcr_source_hint()) {
116 output += indent + " pcr_source_hint: ";
117 base::StringAppendF(&output, "%s",
118 base::HexEncode(value.pcr_source_hint().data(),
119 value.pcr_source_hint().size())
120 .c_str());
121 output += "\n";
122 }
123 output += indent + "}\n";
124 return output;
125 }
126
GetProtoDebugString(const EncryptedData & value)127 std::string GetProtoDebugString(const EncryptedData& value) {
128 return GetProtoDebugStringWithIndent(value, 0);
129 }
130
GetProtoDebugStringWithIndent(const EncryptedData & value,int indent_size)131 std::string GetProtoDebugStringWithIndent(const EncryptedData& value,
132 int indent_size) {
133 std::string indent(indent_size, ' ');
134 std::string output =
135 base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
136
137 if (value.has_wrapped_key()) {
138 output += indent + " wrapped_key: ";
139 base::StringAppendF(
140 &output, "%s",
141 base::HexEncode(value.wrapped_key().data(), value.wrapped_key().size())
142 .c_str());
143 output += "\n";
144 }
145 if (value.has_iv()) {
146 output += indent + " iv: ";
147 base::StringAppendF(
148 &output, "%s",
149 base::HexEncode(value.iv().data(), value.iv().size()).c_str());
150 output += "\n";
151 }
152 if (value.has_mac()) {
153 output += indent + " mac: ";
154 base::StringAppendF(
155 &output, "%s",
156 base::HexEncode(value.mac().data(), value.mac().size()).c_str());
157 output += "\n";
158 }
159 if (value.has_encrypted_data()) {
160 output += indent + " encrypted_data: ";
161 base::StringAppendF(&output, "%s",
162 base::HexEncode(value.encrypted_data().data(),
163 value.encrypted_data().size())
164 .c_str());
165 output += "\n";
166 }
167 if (value.has_wrapping_key_id()) {
168 output += indent + " wrapping_key_id: ";
169 base::StringAppendF(&output, "%s",
170 base::HexEncode(value.wrapping_key_id().data(),
171 value.wrapping_key_id().size())
172 .c_str());
173 output += "\n";
174 }
175 output += indent + "}\n";
176 return output;
177 }
178
GetProtoDebugString(const SignedData & value)179 std::string GetProtoDebugString(const SignedData& value) {
180 return GetProtoDebugStringWithIndent(value, 0);
181 }
182
GetProtoDebugStringWithIndent(const SignedData & value,int indent_size)183 std::string GetProtoDebugStringWithIndent(const SignedData& value,
184 int indent_size) {
185 std::string indent(indent_size, ' ');
186 std::string output =
187 base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
188
189 if (value.has_data()) {
190 output += indent + " data: ";
191 base::StringAppendF(
192 &output, "%s",
193 base::HexEncode(value.data().data(), value.data().size()).c_str());
194 output += "\n";
195 }
196 if (value.has_signature()) {
197 output += indent + " signature: ";
198 base::StringAppendF(&output, "%s", base::HexEncode(value.signature().data(),
199 value.signature().size())
200 .c_str());
201 output += "\n";
202 }
203 output += indent + "}\n";
204 return output;
205 }
206
GetProtoDebugString(const EncryptedIdentityCredential & value)207 std::string GetProtoDebugString(const EncryptedIdentityCredential& value) {
208 return GetProtoDebugStringWithIndent(value, 0);
209 }
210
GetProtoDebugStringWithIndent(const EncryptedIdentityCredential & value,int indent_size)211 std::string GetProtoDebugStringWithIndent(
212 const EncryptedIdentityCredential& value,
213 int indent_size) {
214 std::string indent(indent_size, ' ');
215 std::string output =
216 base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
217
218 if (value.has_asym_ca_contents()) {
219 output += indent + " asym_ca_contents: ";
220 base::StringAppendF(&output, "%s",
221 base::HexEncode(value.asym_ca_contents().data(),
222 value.asym_ca_contents().size())
223 .c_str());
224 output += "\n";
225 }
226 if (value.has_sym_ca_attestation()) {
227 output += indent + " sym_ca_attestation: ";
228 base::StringAppendF(&output, "%s",
229 base::HexEncode(value.sym_ca_attestation().data(),
230 value.sym_ca_attestation().size())
231 .c_str());
232 output += "\n";
233 }
234 output += indent + "}\n";
235 return output;
236 }
237
238 } // namespace attestation
239