1a5af954b516b2524ab9d120d330458e76bfb2f6
[platform/upstream/connectedhomeip.git] / src / lib / asn1 / ASN1Error.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2013-2017 Nest Labs, Inc.
5  *    All rights reserved.
6  *
7  *    Licensed under the Apache License, Version 2.0 (the "License");
8  *    you may not use this file except in compliance with the License.
9  *    You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *    Unless required by applicable law or agreed to in writing, software
14  *    distributed under the License is distributed on an "AS IS" BASIS,
15  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *    See the License for the specific language governing permissions and
17  *    limitations under the License.
18  */
19
20 /**
21  *    @file
22  *      This file defines constants for the CHIP ASN1 subsystem.
23  *
24  *      Error types, ranges, and mappings overrides may be made by
25  *      defining the appropriate ASN1_CONFIG_* or _ASN1_CONFIG_*
26  *      macros.
27  *
28  */
29
30 #pragma once
31
32 #include "ASN1Config.h"
33
34 namespace chip {
35 namespace ASN1 {
36
37 // clang-format off
38
39 /**
40  *  @def ASN1_NO_ERROR
41  *
42  *  @brief
43  *    This defines the InetLayer error code for success or no
44  *    error. This value may be configured via #ASN1_CONFIG_NO_ERROR.
45  *
46  */
47 #define ASN1_NO_ERROR                   ASN1_CONFIG_NO_ERROR
48
49 /**
50  *  @def ASN1_ERROR_MIN
51  *
52  *  @brief
53  *    This defines the base or minimum ASN1 error number range.
54  *    This value may be configured via #ASN1_CONFIG_ERROR_MIN.
55  *
56  */
57 #define ASN1_ERROR_MIN                  ASN1_CONFIG_ERROR_MIN
58
59 /**
60  *  @def ASN1_ERROR_MAX
61  *
62  *  @brief
63  *    This defines the top or maximum ASN1 error number range.
64  *    This value may be configured via #ASN1_CONFIG_ERROR_MAX.
65  *
66  */
67 #define ASN1_ERROR_MAX                  ASN1_CONFIG_ERROR_MAX
68
69 /**
70  *  @def _ASN1_ERROR(e)
71  *
72  *  @brief
73  *    This defines a mapping function for ASN1 errors that allows
74  *    mapping such errors into a platform- or system-specific
75  *    range. This function may be configured via
76  *    #_ASN1_CONFIG_ERROR(e).
77  *
78  *  @param[in]  e  The ASN1 error to map.
79  *
80  *  @return The mapped ASN1 error.
81  *
82  */
83 #define _ASN1_ERROR(e)                  _ASN1_CONFIG_ERROR(e)
84
85 /**
86  *  The basic type for all ASN1 subsystem errors.
87  *
88  *  This is defined to a platform- or system-specific type.
89  *
90  */
91 typedef ASN1_CONFIG_ERROR_TYPE ASN1_ERROR;
92
93
94 /**
95  *  @name Error Definitions
96  *
97  *  @{
98  */
99
100 /**
101  *  @def ASN1_END
102  *
103  *  @brief
104  *    An end of ASN1 container or stream condition occurred.
105  *
106  */
107 #define ASN1_END                        _ASN1_ERROR(0)
108
109 /**
110  *  @def ASN1_ERROR_UNDERRUN
111  *
112  *  @brief
113  *    The ASN.1 encoding ended prematurely.
114  *
115  */
116 #define ASN1_ERROR_UNDERRUN             _ASN1_ERROR(1)
117
118 /**
119  *  @def ASN1_ERROR_OVERFLOW
120  *
121  *  @brief
122  *    The encoding exceeds the available space required to write it.
123  *
124  */
125 #define ASN1_ERROR_OVERFLOW             _ASN1_ERROR(2)
126
127 /**
128  *  @def ASN1_ERROR_INVALID_STATE
129  *
130  *  @brief
131  *    An unexpected or invalid state was encountered.
132  *
133  */
134 #define ASN1_ERROR_INVALID_STATE        _ASN1_ERROR(3)
135
136 /**
137  *  @def ASN1_ERROR_MAX_DEPTH_EXCEEDED
138  *
139  *  @brief
140  *    The maximum number of container reading contexts was exceeded.
141  *
142  */
143 #define ASN1_ERROR_MAX_DEPTH_EXCEEDED   _ASN1_ERROR(4)
144
145 /**
146  *  @def ASN1_ERROR_INVALID_ENCODING
147  *
148  *  @brief
149  *    The ASN.1 encoding is invalid.
150  *
151  */
152 #define ASN1_ERROR_INVALID_ENCODING     _ASN1_ERROR(5)
153
154 /**
155  *  @def ASN1_ERROR_UNSUPPORTED_ENCODING
156  *
157  *  @brief
158  *    An unsupported encoding was requested or encountered.
159  *
160  */
161 #define ASN1_ERROR_UNSUPPORTED_ENCODING _ASN1_ERROR(6)
162
163 /**
164  *  @def ASN1_ERROR_TAG_OVERFLOW
165  *
166  *  @brief
167  *    An encoded tag exceeds the available or allowed space required
168  *    for it.
169  *
170  */
171 #define ASN1_ERROR_TAG_OVERFLOW         _ASN1_ERROR(7)
172
173 /**
174  *  @def ASN1_ERROR_LENGTH_OVERFLOW
175  *
176  *  @brief
177  *    An encoded length exceeds the available or allowed space
178  *    required for it.
179  *
180  */
181 #define ASN1_ERROR_LENGTH_OVERFLOW      _ASN1_ERROR(8)
182
183 /**
184  *  @def ASN1_ERROR_VALUE_OVERFLOW
185  *
186  *  @brief
187  *    An encoded value exceeds the available or allowed space
188  *    required for it.
189  *
190  */
191 #define ASN1_ERROR_VALUE_OVERFLOW       _ASN1_ERROR(9)
192
193 /**
194  *  @def ASN1_ERROR_UNKNOWN_OBJECT_ID
195  *
196  *  @brief
197  *    A requested object identifier does not match the list of
198  *    supported object identifiers.
199  *
200  */
201 #define ASN1_ERROR_UNKNOWN_OBJECT_ID    _ASN1_ERROR(10)
202
203 //                        !!!!! IMPORTANT !!!!!
204 //
205 // If you add new ASN1 errors, please update the translation of error
206 // codes to strings in ASN1Error.cpp, and add them to unittest
207 // in test-apps/TestErrorStr.cpp
208
209 /**
210  *  @}
211  */
212
213 // clang-format on
214
215 bool FormatASN1Error(char * buf, uint16_t bufSize, int32_t err);
216
217 } // namespace ASN1
218 } // namespace chip