• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(&output, "%s",
102                         base::HexEncode(value.quoted_data().data(),
103                                         value.quoted_data().size()).c_str());
104     output += "\n";
105   }
106   if (value.has_quoted_pcr_value()) {
107     output += indent + "  quoted_pcr_value: ";
108     base::StringAppendF(
109         &output, "%s",
110         base::HexEncode(value.quoted_pcr_value().data(),
111                         value.quoted_pcr_value().size()).c_str());
112     output += "\n";
113   }
114   if (value.has_pcr_source_hint()) {
115     output += indent + "  pcr_source_hint: ";
116     base::StringAppendF(
117         &output, "%s", base::HexEncode(value.pcr_source_hint().data(),
118                                        value.pcr_source_hint().size()).c_str());
119     output += "\n";
120   }
121   output += indent + "}\n";
122   return output;
123 }
124 
GetProtoDebugString(const EncryptedData & value)125 std::string GetProtoDebugString(const EncryptedData& value) {
126   return GetProtoDebugStringWithIndent(value, 0);
127 }
128 
GetProtoDebugStringWithIndent(const EncryptedData & value,int indent_size)129 std::string GetProtoDebugStringWithIndent(const EncryptedData& value,
130                                           int indent_size) {
131   std::string indent(indent_size, ' ');
132   std::string output =
133       base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
134 
135   if (value.has_wrapped_key()) {
136     output += indent + "  wrapped_key: ";
137     base::StringAppendF(&output, "%s",
138                         base::HexEncode(value.wrapped_key().data(),
139                                         value.wrapped_key().size()).c_str());
140     output += "\n";
141   }
142   if (value.has_iv()) {
143     output += indent + "  iv: ";
144     base::StringAppendF(
145         &output, "%s",
146         base::HexEncode(value.iv().data(), value.iv().size()).c_str());
147     output += "\n";
148   }
149   if (value.has_mac()) {
150     output += indent + "  mac: ";
151     base::StringAppendF(
152         &output, "%s",
153         base::HexEncode(value.mac().data(), value.mac().size()).c_str());
154     output += "\n";
155   }
156   if (value.has_encrypted_data()) {
157     output += indent + "  encrypted_data: ";
158     base::StringAppendF(&output, "%s",
159                         base::HexEncode(value.encrypted_data().data(),
160                                         value.encrypted_data().size()).c_str());
161     output += "\n";
162   }
163   if (value.has_wrapping_key_id()) {
164     output += indent + "  wrapping_key_id: ";
165     base::StringAppendF(
166         &output, "%s", base::HexEncode(value.wrapping_key_id().data(),
167                                        value.wrapping_key_id().size()).c_str());
168     output += "\n";
169   }
170   output += indent + "}\n";
171   return output;
172 }
173 
GetProtoDebugString(const SignedData & value)174 std::string GetProtoDebugString(const SignedData& value) {
175   return GetProtoDebugStringWithIndent(value, 0);
176 }
177 
GetProtoDebugStringWithIndent(const SignedData & value,int indent_size)178 std::string GetProtoDebugStringWithIndent(const SignedData& value,
179                                           int indent_size) {
180   std::string indent(indent_size, ' ');
181   std::string output =
182       base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
183 
184   if (value.has_data()) {
185     output += indent + "  data: ";
186     base::StringAppendF(
187         &output, "%s",
188         base::HexEncode(value.data().data(), value.data().size()).c_str());
189     output += "\n";
190   }
191   if (value.has_signature()) {
192     output += indent + "  signature: ";
193     base::StringAppendF(&output, "%s",
194                         base::HexEncode(value.signature().data(),
195                                         value.signature().size()).c_str());
196     output += "\n";
197   }
198   output += indent + "}\n";
199   return output;
200 }
201 
GetProtoDebugString(const EncryptedIdentityCredential & value)202 std::string GetProtoDebugString(const EncryptedIdentityCredential& value) {
203   return GetProtoDebugStringWithIndent(value, 0);
204 }
205 
GetProtoDebugStringWithIndent(const EncryptedIdentityCredential & value,int indent_size)206 std::string GetProtoDebugStringWithIndent(
207     const EncryptedIdentityCredential& value,
208     int indent_size) {
209   std::string indent(indent_size, ' ');
210   std::string output =
211       base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
212 
213   if (value.has_asym_ca_contents()) {
214     output += indent + "  asym_ca_contents: ";
215     base::StringAppendF(
216         &output, "%s",
217         base::HexEncode(value.asym_ca_contents().data(),
218                         value.asym_ca_contents().size()).c_str());
219     output += "\n";
220   }
221   if (value.has_sym_ca_attestation()) {
222     output += indent + "  sym_ca_attestation: ";
223     base::StringAppendF(
224         &output, "%s",
225         base::HexEncode(value.sym_ca_attestation().data(),
226                         value.sym_ca_attestation().size()).c_str());
227     output += "\n";
228   }
229   output += indent + "}\n";
230   return output;
231 }
232 
233 }  // namespace attestation
234