3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2019 Google LLC.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * This file contains functions for working with ASN1 errors.
27 #include <asn1/ASN1.h>
28 #include <support/ErrorStr.h>
34 * Given an ASN1 error, returns a human-readable NULL-terminated C string
35 * describing the error.
37 * @param[in] buf Buffer into which the error string will be placed.
38 * @param[in] bufSize Size of the supplied buffer in bytes.
39 * @param[in] err The error to be described.
41 * @return true If a description string was written into the supplied buffer.
42 * @return false If the supplied error was not an ASN1 error.
45 bool FormatASN1Error(char * buf, uint16_t bufSize, int32_t err)
47 const char * desc = nullptr;
49 if (err < ASN1_ERROR_MIN || err > ASN1_ERROR_MAX)
54 #if !CHIP_CONFIG_SHORT_ERROR_STR
58 desc = "End of input";
60 case ASN1_ERROR_UNDERRUN:
61 desc = "Reader underrun";
63 case ASN1_ERROR_OVERFLOW:
64 desc = "Writer overflow";
66 case ASN1_ERROR_INVALID_STATE:
67 desc = "Invalid state";
69 case ASN1_ERROR_MAX_DEPTH_EXCEEDED:
70 desc = "Max depth exceeded";
72 case ASN1_ERROR_INVALID_ENCODING:
73 desc = "Invalid encoding";
75 case ASN1_ERROR_UNSUPPORTED_ENCODING:
76 desc = "Unsupported encoding";
78 case ASN1_ERROR_TAG_OVERFLOW:
79 desc = "Tag overflow";
81 case ASN1_ERROR_LENGTH_OVERFLOW:
82 desc = "Length overflow";
84 case ASN1_ERROR_VALUE_OVERFLOW:
85 desc = "Value overflow";
87 case ASN1_ERROR_UNKNOWN_OBJECT_ID:
88 desc = "Unknown object id";
91 #endif // !CHIP_CONFIG_SHORT_ERROR_STR
93 FormatError(buf, bufSize, "ASN1", err, desc);