errors.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*############################################################################
  2. # Copyright 2016-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 Error reporting implementation.
  19. */
  20. #include <stddef.h>
  21. #include "epid/common/errors.h"
  22. #include "epid/common/stdtypes.h"
  23. /// Record mapping status code to string
  24. struct ErrorTextEntry {
  25. /// error code
  26. EpidStatus value;
  27. /// string associated with error code
  28. char const* text;
  29. };
  30. /// Mapping of status codes to strings
  31. static const struct ErrorTextEntry kEnumToText[] = {
  32. {kEpidNoErr, "no error"},
  33. {kEpidErr, "unspecified error"},
  34. {kEpidSigInvalid, "invalid signature"},
  35. {kEpidSigRevokedInGroupRl, "signature revoked in GroupRl"},
  36. {kEpidSigRevokedInPrivRl, "signature revoked in PrivRl"},
  37. {kEpidSigRevokedInSigRl, "signature revoked in SigRl"},
  38. {kEpidSigRevokedInVerifierRl, "signature revoked in VerifierRl"},
  39. {kEpidNotImpl, "not implemented"},
  40. {kEpidBadArgErr, "bad arguments"},
  41. {kEpidNoMemErr, "could not allocate memory"},
  42. {kEpidMemAllocErr, "insufficient memory provided"},
  43. {kEpidMathErr, "internal math error"},
  44. {kEpidDivByZeroErr, "attempt to divide by zero"},
  45. {kEpidUnderflowErr, "underflow"},
  46. {kEpidHashAlgorithmNotSupported, "unsupported hash algorithm type"},
  47. {kEpidRandMaxIterErr, "reached max iteration for random number generation"},
  48. {kEpidDuplicateErr, "argument would add duplicate entry"},
  49. {kEpidInconsistentBasenameSetErr,
  50. "the set basename is inconsistent with supplied parameters"}};
  51. char const* EpidStatusToString(EpidStatus e) {
  52. size_t i = 0;
  53. const size_t num_entries = sizeof(kEnumToText) / sizeof(kEnumToText[0]);
  54. for (i = 0; i < num_entries; i++) {
  55. if (e == kEnumToText[i].value) {
  56. return kEnumToText[i].text;
  57. }
  58. }
  59. return "unknown error";
  60. }