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