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