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_interface_proto.h"
20
21#include <string>
22
23#include <base/strings/string_number_conversions.h>
24#include <base/strings/stringprintf.h>
25
26#include "attestation/common/print_common_proto.h"
27
28namespace attestation {
29
30std::string GetProtoDebugString(AttestationStatus value) {
31  return GetProtoDebugStringWithIndent(value, 0);
32}
33
34std::string GetProtoDebugStringWithIndent(AttestationStatus value,
35                                          int indent_size) {
36  if (value == STATUS_SUCCESS) {
37    return "STATUS_SUCCESS";
38  }
39  if (value == STATUS_UNEXPECTED_DEVICE_ERROR) {
40    return "STATUS_UNEXPECTED_DEVICE_ERROR";
41  }
42  if (value == STATUS_NOT_AVAILABLE) {
43    return "STATUS_NOT_AVAILABLE";
44  }
45  if (value == STATUS_NOT_READY) {
46    return "STATUS_NOT_READY";
47  }
48  if (value == STATUS_NOT_ALLOWED) {
49    return "STATUS_NOT_ALLOWED";
50  }
51  if (value == STATUS_INVALID_PARAMETER) {
52    return "STATUS_INVALID_PARAMETER";
53  }
54  if (value == STATUS_REQUEST_DENIED_BY_CA) {
55    return "STATUS_REQUEST_DENIED_BY_CA";
56  }
57  if (value == STATUS_CA_NOT_AVAILABLE) {
58    return "STATUS_CA_NOT_AVAILABLE";
59  }
60  return "<unknown>";
61}
62
63std::string GetProtoDebugString(const CreateGoogleAttestedKeyRequest& value) {
64  return GetProtoDebugStringWithIndent(value, 0);
65}
66
67std::string GetProtoDebugStringWithIndent(
68    const CreateGoogleAttestedKeyRequest& value,
69    int indent_size) {
70  std::string indent(indent_size, ' ');
71  std::string output =
72      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
73
74  if (value.has_key_label()) {
75    output += indent + "  key_label: ";
76    base::StringAppendF(&output, "%s", value.key_label().c_str());
77    output += "\n";
78  }
79  if (value.has_key_type()) {
80    output += indent + "  key_type: ";
81    base::StringAppendF(&output, "%s",
82                        GetProtoDebugStringWithIndent(value.key_type(),
83                                                      indent_size + 2).c_str());
84    output += "\n";
85  }
86  if (value.has_key_usage()) {
87    output += indent + "  key_usage: ";
88    base::StringAppendF(&output, "%s",
89                        GetProtoDebugStringWithIndent(value.key_usage(),
90                                                      indent_size + 2).c_str());
91    output += "\n";
92  }
93  if (value.has_certificate_profile()) {
94    output += indent + "  certificate_profile: ";
95    base::StringAppendF(&output, "%s", GetProtoDebugStringWithIndent(
96                                           value.certificate_profile(),
97                                           indent_size + 2).c_str());
98    output += "\n";
99  }
100  if (value.has_username()) {
101    output += indent + "  username: ";
102    base::StringAppendF(&output, "%s", value.username().c_str());
103    output += "\n";
104  }
105  if (value.has_origin()) {
106    output += indent + "  origin: ";
107    base::StringAppendF(&output, "%s", value.origin().c_str());
108    output += "\n";
109  }
110  output += indent + "}\n";
111  return output;
112}
113
114std::string GetProtoDebugString(const CreateGoogleAttestedKeyReply& value) {
115  return GetProtoDebugStringWithIndent(value, 0);
116}
117
118std::string GetProtoDebugStringWithIndent(
119    const CreateGoogleAttestedKeyReply& value,
120    int indent_size) {
121  std::string indent(indent_size, ' ');
122  std::string output =
123      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
124
125  if (value.has_status()) {
126    output += indent + "  status: ";
127    base::StringAppendF(
128        &output, "%s",
129        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
130    output += "\n";
131  }
132  if (value.has_server_error()) {
133    output += indent + "  server_error: ";
134    base::StringAppendF(&output, "%s", value.server_error().c_str());
135    output += "\n";
136  }
137  if (value.has_certificate_chain()) {
138    output += indent + "  certificate_chain: ";
139    base::StringAppendF(&output, "%s", value.certificate_chain().c_str());
140    output += "\n";
141  }
142  output += indent + "}\n";
143  return output;
144}
145
146std::string GetProtoDebugString(const GetKeyInfoRequest& value) {
147  return GetProtoDebugStringWithIndent(value, 0);
148}
149
150std::string GetProtoDebugStringWithIndent(const GetKeyInfoRequest& value,
151                                          int indent_size) {
152  std::string indent(indent_size, ' ');
153  std::string output =
154      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
155
156  if (value.has_key_label()) {
157    output += indent + "  key_label: ";
158    base::StringAppendF(&output, "%s", value.key_label().c_str());
159    output += "\n";
160  }
161  if (value.has_username()) {
162    output += indent + "  username: ";
163    base::StringAppendF(&output, "%s", value.username().c_str());
164    output += "\n";
165  }
166  output += indent + "}\n";
167  return output;
168}
169
170std::string GetProtoDebugString(const GetKeyInfoReply& value) {
171  return GetProtoDebugStringWithIndent(value, 0);
172}
173
174std::string GetProtoDebugStringWithIndent(const GetKeyInfoReply& value,
175                                          int indent_size) {
176  std::string indent(indent_size, ' ');
177  std::string output =
178      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
179
180  if (value.has_status()) {
181    output += indent + "  status: ";
182    base::StringAppendF(
183        &output, "%s",
184        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
185    output += "\n";
186  }
187  if (value.has_key_type()) {
188    output += indent + "  key_type: ";
189    base::StringAppendF(&output, "%s",
190                        GetProtoDebugStringWithIndent(value.key_type(),
191                                                      indent_size + 2).c_str());
192    output += "\n";
193  }
194  if (value.has_key_usage()) {
195    output += indent + "  key_usage: ";
196    base::StringAppendF(&output, "%s",
197                        GetProtoDebugStringWithIndent(value.key_usage(),
198                                                      indent_size + 2).c_str());
199    output += "\n";
200  }
201  if (value.has_public_key()) {
202    output += indent + "  public_key: ";
203    base::StringAppendF(&output, "%s",
204                        base::HexEncode(value.public_key().data(),
205                                        value.public_key().size()).c_str());
206    output += "\n";
207  }
208  if (value.has_certify_info()) {
209    output += indent + "  certify_info: ";
210    base::StringAppendF(&output, "%s",
211                        base::HexEncode(value.certify_info().data(),
212                                        value.certify_info().size()).c_str());
213    output += "\n";
214  }
215  if (value.has_certify_info_signature()) {
216    output += indent + "  certify_info_signature: ";
217    base::StringAppendF(
218        &output, "%s",
219        base::HexEncode(value.certify_info_signature().data(),
220                        value.certify_info_signature().size()).c_str());
221    output += "\n";
222  }
223  if (value.has_certificate()) {
224    output += indent + "  certificate: ";
225    base::StringAppendF(&output, "%s",
226                        base::HexEncode(value.certificate().data(),
227                                        value.certificate().size()).c_str());
228    output += "\n";
229  }
230  output += indent + "}\n";
231  return output;
232}
233
234std::string GetProtoDebugString(const GetEndorsementInfoRequest& value) {
235  return GetProtoDebugStringWithIndent(value, 0);
236}
237
238std::string GetProtoDebugStringWithIndent(
239    const GetEndorsementInfoRequest& value,
240    int indent_size) {
241  std::string indent(indent_size, ' ');
242  std::string output =
243      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
244
245  if (value.has_key_type()) {
246    output += indent + "  key_type: ";
247    base::StringAppendF(&output, "%s",
248                        GetProtoDebugStringWithIndent(value.key_type(),
249                                                      indent_size + 2).c_str());
250    output += "\n";
251  }
252  output += indent + "}\n";
253  return output;
254}
255
256std::string GetProtoDebugString(const GetEndorsementInfoReply& value) {
257  return GetProtoDebugStringWithIndent(value, 0);
258}
259
260std::string GetProtoDebugStringWithIndent(const GetEndorsementInfoReply& value,
261                                          int indent_size) {
262  std::string indent(indent_size, ' ');
263  std::string output =
264      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
265
266  if (value.has_status()) {
267    output += indent + "  status: ";
268    base::StringAppendF(
269        &output, "%s",
270        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
271    output += "\n";
272  }
273  if (value.has_ek_public_key()) {
274    output += indent + "  ek_public_key: ";
275    base::StringAppendF(&output, "%s",
276                        base::HexEncode(value.ek_public_key().data(),
277                                        value.ek_public_key().size()).c_str());
278    output += "\n";
279  }
280  if (value.has_ek_certificate()) {
281    output += indent + "  ek_certificate: ";
282    base::StringAppendF(&output, "%s",
283                        base::HexEncode(value.ek_certificate().data(),
284                                        value.ek_certificate().size()).c_str());
285    output += "\n";
286  }
287  output += indent + "}\n";
288  return output;
289}
290
291std::string GetProtoDebugString(const GetAttestationKeyInfoRequest& value) {
292  return GetProtoDebugStringWithIndent(value, 0);
293}
294
295std::string GetProtoDebugStringWithIndent(
296    const GetAttestationKeyInfoRequest& value,
297    int indent_size) {
298  std::string indent(indent_size, ' ');
299  std::string output =
300      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
301
302  if (value.has_key_type()) {
303    output += indent + "  key_type: ";
304    base::StringAppendF(&output, "%s",
305                        GetProtoDebugStringWithIndent(value.key_type(),
306                                                      indent_size + 2).c_str());
307    output += "\n";
308  }
309  output += indent + "}\n";
310  return output;
311}
312
313std::string GetProtoDebugString(const GetAttestationKeyInfoReply& value) {
314  return GetProtoDebugStringWithIndent(value, 0);
315}
316
317std::string GetProtoDebugStringWithIndent(
318    const GetAttestationKeyInfoReply& value,
319    int indent_size) {
320  std::string indent(indent_size, ' ');
321  std::string output =
322      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
323
324  if (value.has_status()) {
325    output += indent + "  status: ";
326    base::StringAppendF(
327        &output, "%s",
328        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
329    output += "\n";
330  }
331  if (value.has_public_key()) {
332    output += indent + "  public_key: ";
333    base::StringAppendF(&output, "%s",
334                        base::HexEncode(value.public_key().data(),
335                                        value.public_key().size()).c_str());
336    output += "\n";
337  }
338  if (value.has_public_key_tpm_format()) {
339    output += indent + "  public_key_tpm_format: ";
340    base::StringAppendF(
341        &output, "%s",
342        base::HexEncode(value.public_key_tpm_format().data(),
343                        value.public_key_tpm_format().size()).c_str());
344    output += "\n";
345  }
346  if (value.has_certificate()) {
347    output += indent + "  certificate: ";
348    base::StringAppendF(&output, "%s",
349                        base::HexEncode(value.certificate().data(),
350                                        value.certificate().size()).c_str());
351    output += "\n";
352  }
353  if (value.has_pcr0_quote()) {
354    output += indent + "  pcr0_quote: ";
355    base::StringAppendF(&output, "%s",
356                        GetProtoDebugStringWithIndent(value.pcr0_quote(),
357                                                      indent_size + 2).c_str());
358    output += "\n";
359  }
360  if (value.has_pcr1_quote()) {
361    output += indent + "  pcr1_quote: ";
362    base::StringAppendF(&output, "%s",
363                        GetProtoDebugStringWithIndent(value.pcr1_quote(),
364                                                      indent_size + 2).c_str());
365    output += "\n";
366  }
367  output += indent + "}\n";
368  return output;
369}
370
371std::string GetProtoDebugString(const ActivateAttestationKeyRequest& value) {
372  return GetProtoDebugStringWithIndent(value, 0);
373}
374
375std::string GetProtoDebugStringWithIndent(
376    const ActivateAttestationKeyRequest& value,
377    int indent_size) {
378  std::string indent(indent_size, ' ');
379  std::string output =
380      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
381
382  if (value.has_key_type()) {
383    output += indent + "  key_type: ";
384    base::StringAppendF(&output, "%s",
385                        GetProtoDebugStringWithIndent(value.key_type(),
386                                                      indent_size + 2).c_str());
387    output += "\n";
388  }
389  if (value.has_encrypted_certificate()) {
390    output += indent + "  encrypted_certificate: ";
391    base::StringAppendF(&output, "%s", GetProtoDebugStringWithIndent(
392                                           value.encrypted_certificate(),
393                                           indent_size + 2).c_str());
394    output += "\n";
395  }
396  if (value.has_save_certificate()) {
397    output += indent + "  save_certificate: ";
398    base::StringAppendF(&output, "%s",
399                        value.save_certificate() ? "true" : "false");
400    output += "\n";
401  }
402  output += indent + "}\n";
403  return output;
404}
405
406std::string GetProtoDebugString(const ActivateAttestationKeyReply& value) {
407  return GetProtoDebugStringWithIndent(value, 0);
408}
409
410std::string GetProtoDebugStringWithIndent(
411    const ActivateAttestationKeyReply& value,
412    int indent_size) {
413  std::string indent(indent_size, ' ');
414  std::string output =
415      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
416
417  if (value.has_status()) {
418    output += indent + "  status: ";
419    base::StringAppendF(
420        &output, "%s",
421        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
422    output += "\n";
423  }
424  if (value.has_certificate()) {
425    output += indent + "  certificate: ";
426    base::StringAppendF(&output, "%s",
427                        base::HexEncode(value.certificate().data(),
428                                        value.certificate().size()).c_str());
429    output += "\n";
430  }
431  output += indent + "}\n";
432  return output;
433}
434
435std::string GetProtoDebugString(const CreateCertifiableKeyRequest& value) {
436  return GetProtoDebugStringWithIndent(value, 0);
437}
438
439std::string GetProtoDebugStringWithIndent(
440    const CreateCertifiableKeyRequest& value,
441    int indent_size) {
442  std::string indent(indent_size, ' ');
443  std::string output =
444      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
445
446  if (value.has_key_label()) {
447    output += indent + "  key_label: ";
448    base::StringAppendF(&output, "%s", value.key_label().c_str());
449    output += "\n";
450  }
451  if (value.has_username()) {
452    output += indent + "  username: ";
453    base::StringAppendF(&output, "%s", value.username().c_str());
454    output += "\n";
455  }
456  if (value.has_key_type()) {
457    output += indent + "  key_type: ";
458    base::StringAppendF(&output, "%s",
459                        GetProtoDebugStringWithIndent(value.key_type(),
460                                                      indent_size + 2).c_str());
461    output += "\n";
462  }
463  if (value.has_key_usage()) {
464    output += indent + "  key_usage: ";
465    base::StringAppendF(&output, "%s",
466                        GetProtoDebugStringWithIndent(value.key_usage(),
467                                                      indent_size + 2).c_str());
468    output += "\n";
469  }
470  output += indent + "}\n";
471  return output;
472}
473
474std::string GetProtoDebugString(const CreateCertifiableKeyReply& value) {
475  return GetProtoDebugStringWithIndent(value, 0);
476}
477
478std::string GetProtoDebugStringWithIndent(
479    const CreateCertifiableKeyReply& value,
480    int indent_size) {
481  std::string indent(indent_size, ' ');
482  std::string output =
483      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
484
485  if (value.has_status()) {
486    output += indent + "  status: ";
487    base::StringAppendF(
488        &output, "%s",
489        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
490    output += "\n";
491  }
492  if (value.has_public_key()) {
493    output += indent + "  public_key: ";
494    base::StringAppendF(&output, "%s",
495                        base::HexEncode(value.public_key().data(),
496                                        value.public_key().size()).c_str());
497    output += "\n";
498  }
499  if (value.has_certify_info()) {
500    output += indent + "  certify_info: ";
501    base::StringAppendF(&output, "%s",
502                        base::HexEncode(value.certify_info().data(),
503                                        value.certify_info().size()).c_str());
504    output += "\n";
505  }
506  if (value.has_certify_info_signature()) {
507    output += indent + "  certify_info_signature: ";
508    base::StringAppendF(
509        &output, "%s",
510        base::HexEncode(value.certify_info_signature().data(),
511                        value.certify_info_signature().size()).c_str());
512    output += "\n";
513  }
514  output += indent + "}\n";
515  return output;
516}
517
518std::string GetProtoDebugString(const DecryptRequest& value) {
519  return GetProtoDebugStringWithIndent(value, 0);
520}
521
522std::string GetProtoDebugStringWithIndent(const DecryptRequest& value,
523                                          int indent_size) {
524  std::string indent(indent_size, ' ');
525  std::string output =
526      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
527
528  if (value.has_key_label()) {
529    output += indent + "  key_label: ";
530    base::StringAppendF(&output, "%s", value.key_label().c_str());
531    output += "\n";
532  }
533  if (value.has_username()) {
534    output += indent + "  username: ";
535    base::StringAppendF(&output, "%s", value.username().c_str());
536    output += "\n";
537  }
538  if (value.has_encrypted_data()) {
539    output += indent + "  encrypted_data: ";
540    base::StringAppendF(&output, "%s",
541                        base::HexEncode(value.encrypted_data().data(),
542                                        value.encrypted_data().size()).c_str());
543    output += "\n";
544  }
545  output += indent + "}\n";
546  return output;
547}
548
549std::string GetProtoDebugString(const DecryptReply& value) {
550  return GetProtoDebugStringWithIndent(value, 0);
551}
552
553std::string GetProtoDebugStringWithIndent(const DecryptReply& value,
554                                          int indent_size) {
555  std::string indent(indent_size, ' ');
556  std::string output =
557      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
558
559  if (value.has_status()) {
560    output += indent + "  status: ";
561    base::StringAppendF(
562        &output, "%s",
563        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
564    output += "\n";
565  }
566  if (value.has_decrypted_data()) {
567    output += indent + "  decrypted_data: ";
568    base::StringAppendF(&output, "%s",
569                        base::HexEncode(value.decrypted_data().data(),
570                                        value.decrypted_data().size()).c_str());
571    output += "\n";
572  }
573  output += indent + "}\n";
574  return output;
575}
576
577std::string GetProtoDebugString(const SignRequest& value) {
578  return GetProtoDebugStringWithIndent(value, 0);
579}
580
581std::string GetProtoDebugStringWithIndent(const SignRequest& value,
582                                          int indent_size) {
583  std::string indent(indent_size, ' ');
584  std::string output =
585      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
586
587  if (value.has_key_label()) {
588    output += indent + "  key_label: ";
589    base::StringAppendF(&output, "%s", value.key_label().c_str());
590    output += "\n";
591  }
592  if (value.has_username()) {
593    output += indent + "  username: ";
594    base::StringAppendF(&output, "%s", value.username().c_str());
595    output += "\n";
596  }
597  if (value.has_data_to_sign()) {
598    output += indent + "  data_to_sign: ";
599    base::StringAppendF(&output, "%s",
600                        base::HexEncode(value.data_to_sign().data(),
601                                        value.data_to_sign().size()).c_str());
602    output += "\n";
603  }
604  output += indent + "}\n";
605  return output;
606}
607
608std::string GetProtoDebugString(const SignReply& value) {
609  return GetProtoDebugStringWithIndent(value, 0);
610}
611
612std::string GetProtoDebugStringWithIndent(const SignReply& value,
613                                          int indent_size) {
614  std::string indent(indent_size, ' ');
615  std::string output =
616      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
617
618  if (value.has_status()) {
619    output += indent + "  status: ";
620    base::StringAppendF(
621        &output, "%s",
622        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
623    output += "\n";
624  }
625  if (value.has_signature()) {
626    output += indent + "  signature: ";
627    base::StringAppendF(&output, "%s",
628                        base::HexEncode(value.signature().data(),
629                                        value.signature().size()).c_str());
630    output += "\n";
631  }
632  output += indent + "}\n";
633  return output;
634}
635
636std::string GetProtoDebugString(const RegisterKeyWithChapsTokenRequest& value) {
637  return GetProtoDebugStringWithIndent(value, 0);
638}
639
640std::string GetProtoDebugStringWithIndent(
641    const RegisterKeyWithChapsTokenRequest& value,
642    int indent_size) {
643  std::string indent(indent_size, ' ');
644  std::string output =
645      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
646
647  if (value.has_key_label()) {
648    output += indent + "  key_label: ";
649    base::StringAppendF(&output, "%s", value.key_label().c_str());
650    output += "\n";
651  }
652  if (value.has_username()) {
653    output += indent + "  username: ";
654    base::StringAppendF(&output, "%s", value.username().c_str());
655    output += "\n";
656  }
657  output += indent + "}\n";
658  return output;
659}
660
661std::string GetProtoDebugString(const RegisterKeyWithChapsTokenReply& value) {
662  return GetProtoDebugStringWithIndent(value, 0);
663}
664
665std::string GetProtoDebugStringWithIndent(
666    const RegisterKeyWithChapsTokenReply& value,
667    int indent_size) {
668  std::string indent(indent_size, ' ');
669  std::string output =
670      base::StringPrintf("[%s] {\n", value.GetTypeName().c_str());
671
672  if (value.has_status()) {
673    output += indent + "  status: ";
674    base::StringAppendF(
675        &output, "%s",
676        GetProtoDebugStringWithIndent(value.status(), indent_size + 2).c_str());
677    output += "\n";
678  }
679  output += indent + "}\n";
680  return output;
681}
682
683}  // namespace attestation
684