epid_gtest-testhelper.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*############################################################################
  2. # Copyright 2017 Intel Corporation
  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. * \file
  18. * \brief Implementation of Intel(R) EPID specific predicates for gtest
  19. */
  20. #include "epid/common-testhelper/epid_gtest-testhelper.h"
  21. #include <string>
  22. /// Record mapping status code to string
  23. struct EpidStatusTextEntry {
  24. /// error code
  25. EpidStatus value;
  26. /// name of error code
  27. const char* value_name;
  28. };
  29. #define EPID_STATUS_TEXT_ENTRY_VALUE(sts) \
  30. { sts, #sts }
  31. /// Mapping of status codes to strings
  32. static const struct EpidStatusTextEntry kEnumToText[] = {
  33. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidNoErr),
  34. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidErr),
  35. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigInvalid),
  36. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigRevokedInGroupRl),
  37. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigRevokedInPrivRl),
  38. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigRevokedInSigRl),
  39. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidSigRevokedInVerifierRl),
  40. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidNotImpl),
  41. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidBadArgErr),
  42. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidNoMemErr),
  43. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidMemAllocErr),
  44. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidMathErr),
  45. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidDivByZeroErr),
  46. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidUnderflowErr),
  47. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidHashAlgorithmNotSupported),
  48. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidRandMaxIterErr),
  49. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidDuplicateErr),
  50. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidInconsistentBasenameSetErr),
  51. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidMathQuadraticNonResidueError),
  52. EPID_STATUS_TEXT_ENTRY_VALUE(kEpidOutOfSequenceError)};
  53. const char* EpidStatusToName(EpidStatus e) {
  54. size_t i = 0;
  55. const size_t num_entries = sizeof(kEnumToText) / sizeof(kEnumToText[0]);
  56. for (i = 0; i < num_entries; i++) {
  57. if (e == kEnumToText[i].value) {
  58. return kEnumToText[i].value_name;
  59. }
  60. }
  61. return "unknown";
  62. }
  63. std::ostream& operator<<(std::ostream& os, EpidStatus e) {
  64. const char* enum_name = EpidStatusToName(e);
  65. return os << enum_name << " (" << std::to_string(e) << ")";
  66. }