renamed 'hf mfdes readdata, writedata' to 'read/write'
[RRG-proxmark3.git] / client / deps / tinycbor / cborerrorstrings.c
blobc37d05ac16e933e909b3742ddf020dfc1979105e
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Intel Corporation
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
12 ** The above copyright notice and this permission notice shall be included in
13 ** all copies or substantial portions of the Software.
15 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 ** THE SOFTWARE.
23 ****************************************************************************/
25 #include "cbor.h"
27 #ifndef _
28 # define _(msg) msg
29 #endif
31 /**
32 * \enum CborError
33 * \ingroup CborGlobals
34 * The CborError enum contains the possible error values used by the CBOR encoder and decoder.
36 * TinyCBOR functions report success by returning CborNoError, or one error
37 * condition by returning one of the values below. One exception is the
38 * out-of-memory condition (CborErrorOutOfMemory), which the functions for \ref
39 * CborEncoding may report in bit-wise OR with other conditions.
41 * This technique allows code to determine whether the only error condition was
42 * a lack of buffer space, which may not be a fatal condition if the buffer can
43 * be resized. Additionally, the functions for \ref CborEncoding may continue
44 * to be used even after CborErrorOutOfMemory is returned, and instead they
45 * will simply calculate the extra space needed.
47 * \value CborNoError No error occurred
48 * \omitvalue CborUnknownError
49 * \value CborErrorUnknownLength Request for the length of an array, map or string whose length is not provided in the CBOR stream
50 * \value CborErrorAdvancePastEOF Not enough data in the stream to decode item (decoding would advance past end of stream)
51 * \value CborErrorIO An I/O error occurred, probably due to an out-of-memory situation
52 * \value CborErrorGarbageAtEnd Bytes exist past the end of the CBOR stream
53 * \value CborErrorUnexpectedEOF End of stream reached unexpectedly
54 * \value CborErrorUnexpectedBreak A CBOR break byte was found where not expected
55 * \value CborErrorUnknownType An unknown type (future extension to CBOR) was found in the stream
56 * \value CborErrorIllegalType An invalid type was found while parsing a chunked CBOR string
57 * \value CborErrorIllegalNumber An illegal initial byte (encoding unspecified additional information) was found
58 * \value CborErrorIllegalSimpleType An illegal encoding of a CBOR Simple Type of value less than 32 was found
59 * \omitvalue CborErrorUnknownSimpleType
60 * \omitvalue CborErrorUnknownTag
61 * \omitvalue CborErrorInappropriateTagForType
62 * \omitvalue CborErrorDuplicateObjectKeys
63 * \value CborErrorInvalidUtf8TextString Illegal UTF-8 encoding found while parsing CBOR Text String
64 * \value CborErrorTooManyItems Too many items were added to CBOR map or array of pre-determined length
65 * \value CborErrorTooFewItems Too few items were added to CBOR map or array of pre-determined length
66 * \value CborErrorDataTooLarge Data item size exceeds TinyCBOR's implementation limits
67 * \value CborErrorNestingTooDeep Data item nesting exceeds TinyCBOR's implementation limits
68 * \omitvalue CborErrorUnsupportedType
69 * \value CborErrorJsonObjectKeyIsAggregate Conversion to JSON failed because the key in a map is a CBOR map or array
70 * \value CborErrorJsonObjectKeyNotString Conversion to JSON failed because the key in a map is not a text string
71 * \value CborErrorOutOfMemory During CBOR encoding, the buffer provided is insufficient for encoding the data item;
72 * in other situations, TinyCBOR failed to allocate memory
73 * \value CborErrorInternalError An internal error occurred in TinyCBOR
76 /**
77 * \ingroup CborGlobals
78 * Returns the error string corresponding to the CBOR error condition \a error.
80 const char *cbor_error_string(CborError error) {
81 switch (error) {
82 case CborNoError:
83 return "";
85 case CborUnknownError:
86 return _("unknown error");
88 case CborErrorOutOfMemory:
89 return _("out of memory/need more memory");
91 case CborErrorUnknownLength:
92 return _("unknown length (attempted to get the length of a map/array/string of indeterminate length");
94 case CborErrorAdvancePastEOF:
95 return _("attempted to advance past EOF");
97 case CborErrorIO:
98 return _("I/O error");
100 case CborErrorGarbageAtEnd:
101 return _("garbage after the end of the content");
103 case CborErrorUnexpectedEOF:
104 return _("unexpected end of data");
106 case CborErrorUnexpectedBreak:
107 return _("unexpected 'break' byte");
109 case CborErrorUnknownType:
110 return _("illegal byte (encodes future extension type)");
112 case CborErrorIllegalType:
113 return _("mismatched string type in chunked string");
115 case CborErrorIllegalNumber:
116 return _("illegal initial byte (encodes unspecified additional information)");
118 case CborErrorIllegalSimpleType:
119 return _("illegal encoding of simple type smaller than 32");
121 case CborErrorUnknownSimpleType:
122 return _("unknown simple type");
124 case CborErrorUnknownTag:
125 return _("unknown tag");
127 case CborErrorInappropriateTagForType:
128 return _("inappropriate tag for type");
130 case CborErrorDuplicateObjectKeys:
131 return _("duplicate keys in object");
133 case CborErrorInvalidUtf8TextString:
134 return _("invalid UTF-8 content in string");
136 case CborErrorExcludedType:
137 return _("excluded type found");
139 case CborErrorExcludedValue:
140 return _("excluded value found");
142 case CborErrorImproperValue:
143 case CborErrorOverlongEncoding:
144 return _("value encoded in non-canonical form");
146 case CborErrorMapKeyNotString:
147 case CborErrorJsonObjectKeyNotString:
148 return _("key in map is not a string");
150 case CborErrorMapNotSorted:
151 return _("map is not sorted");
153 case CborErrorMapKeysNotUnique:
154 return _("map keys are not unique");
156 case CborErrorTooManyItems:
157 return _("too many items added to encoder");
159 case CborErrorTooFewItems:
160 return _("too few items added to encoder");
162 case CborErrorDataTooLarge:
163 return _("internal error: data too large");
165 case CborErrorNestingTooDeep:
166 return _("internal error: too many nested containers found in recursive function");
168 case CborErrorUnsupportedType:
169 return _("unsupported type");
171 case CborErrorJsonObjectKeyIsAggregate:
172 return _("conversion to JSON failed: key in object is an array or map");
174 case CborErrorJsonNotImplemented:
175 return _("conversion to JSON failed: open_memstream unavailable");
177 case CborErrorInternalError:
178 return _("internal error");
180 return cbor_error_string(CborUnknownError);