LCOV - code coverage report
Current view: top level - lib/asn1 - ASN1Error.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 0 40 0.0 %
Date: 2024-02-15 08:20:41 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2020 Project CHIP Authors
       4             :  *    Copyright (c) 2019 Google LLC.
       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 contains functions for working with ASN1 errors.
      23             :  */
      24             : 
      25             : #include <stdlib.h>
      26             : 
      27             : #include <lib/asn1/ASN1.h>
      28             : 
      29             : namespace chip {
      30             : namespace ASN1 {
      31             : 
      32             : /**
      33             :  * Given an ASN1 error, returns a human-readable NULL-terminated C string
      34             :  * describing the error.
      35             :  *
      36             :  * @param[in] buf                   Buffer into which the error string will be placed.
      37             :  * @param[in] bufSize               Size of the supplied buffer in bytes.
      38             :  * @param[in] err                   The error to be described.
      39             :  *
      40             :  * @return true                     If a description string was written into the supplied buffer.
      41             :  * @return false                    If the supplied error was not an ASN1 error.
      42             :  *
      43             :  */
      44           0 : bool FormatASN1Error(char * buf, uint16_t bufSize, CHIP_ERROR err)
      45             : {
      46           0 :     const char * desc = nullptr;
      47             : 
      48           0 :     if (!err.IsPart(ChipError::SdkPart::kASN1))
      49             :     {
      50           0 :         return false;
      51             :     }
      52             : 
      53             : #if !CHIP_CONFIG_SHORT_ERROR_STR
      54           0 :     switch (err.AsInteger())
      55             :     {
      56           0 :     case ASN1_END.AsInteger():
      57           0 :         desc = "End of input";
      58           0 :         break;
      59           0 :     case ASN1_ERROR_UNDERRUN.AsInteger():
      60           0 :         desc = "Reader underrun";
      61           0 :         break;
      62           0 :     case ASN1_ERROR_OVERFLOW.AsInteger():
      63           0 :         desc = "Writer overflow";
      64           0 :         break;
      65           0 :     case ASN1_ERROR_INVALID_STATE.AsInteger():
      66           0 :         desc = "Invalid state";
      67           0 :         break;
      68           0 :     case ASN1_ERROR_MAX_DEPTH_EXCEEDED.AsInteger():
      69           0 :         desc = "Max depth exceeded";
      70           0 :         break;
      71           0 :     case ASN1_ERROR_INVALID_ENCODING.AsInteger():
      72           0 :         desc = "Invalid encoding";
      73           0 :         break;
      74           0 :     case ASN1_ERROR_UNSUPPORTED_ENCODING.AsInteger():
      75           0 :         desc = "Unsupported encoding";
      76           0 :         break;
      77           0 :     case ASN1_ERROR_TAG_OVERFLOW.AsInteger():
      78           0 :         desc = "Tag overflow";
      79           0 :         break;
      80           0 :     case ASN1_ERROR_LENGTH_OVERFLOW.AsInteger():
      81           0 :         desc = "Length overflow";
      82           0 :         break;
      83           0 :     case ASN1_ERROR_VALUE_OVERFLOW.AsInteger():
      84           0 :         desc = "Value overflow";
      85           0 :         break;
      86           0 :     case ASN1_ERROR_UNKNOWN_OBJECT_ID.AsInteger():
      87           0 :         desc = "Unknown object id";
      88           0 :         break;
      89             :     }
      90             : #endif // !CHIP_CONFIG_SHORT_ERROR_STR
      91             : 
      92           0 :     FormatError(buf, bufSize, "ASN1", err, desc);
      93             : 
      94           0 :     return true;
      95             : }
      96             : 
      97             : } // namespace ASN1
      98             : } // namespace chip

Generated by: LCOV version 1.14