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