Matter SDK Coverage Report
Current view: top level - setup_payload - QRCodeSetupPayloadParser.h (source / functions) Coverage Total Hit
Test: SHA:85ccc7ecb1e237989acbce8496879fb5f8defb24 Lines: 100.0 % 1 1
Test Date: 2025-06-19 07:09:10 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /**
       2              :  *
       3              :  *    Copyright (c) 2020 Project CHIP Authors
       4              :  *
       5              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6              :  *    you may not use this file except in compliance with the License.
       7              :  *    You may obtain a copy of the License at
       8              :  *
       9              :  *        http://www.apache.org/licenses/LICENSE-2.0
      10              :  *
      11              :  *    Unless required by applicable law or agreed to in writing, software
      12              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14              :  *    See the License for the specific language governing permissions and
      15              :  *    limitations under the License.
      16              :  */
      17              : 
      18              : /**
      19              :  *    @file
      20              :  *      This file describes a QRCode Setup Payload parser based on the
      21              :  *      CHIP specification.
      22              :  */
      23              : 
      24              : #pragma once
      25              : 
      26              : #include "SetupPayload.h"
      27              : 
      28              : #include <lib/core/CHIPError.h>
      29              : #include <lib/core/TLV.h>
      30              : 
      31              : #include <string>
      32              : #include <utility>
      33              : 
      34              : namespace chip {
      35              : 
      36              : /**
      37              :  * @class QRCodeSetupPayloadParser
      38              :  * A class that can be used to convert a base38 encoded payload to a SetupPayload object
      39              :  * */
      40              : class QRCodeSetupPayloadParser
      41              : {
      42              : private:
      43              :     std::string mBase38Representation;
      44              : 
      45              : public:
      46              :     /**
      47              :      * base38Representation is expected to start with the "MT:" prefix, in general.
      48              :      */
      49            5 :     QRCodeSetupPayloadParser(std::string base38Representation) : mBase38Representation(std::move(base38Representation)) {}
      50              : 
      51              :     /**
      52              :      * Populate the payload based on the provided base38 representation.  If the
      53              :      * provided representation contains concatenated payloads, this method will
      54              :      * fail.
      55              :      */
      56              :     CHIP_ERROR populatePayload(SetupPayload & outPayload);
      57              : 
      58              :     /**
      59              :      * Populate the provided list of payloads.  This can handle concatenated payloads, and should
      60              :      * generally be preferred to populatePayload unless the payload is known to not be a
      61              :      * concatenated one.
      62              :      *
      63              :      * On success, the contents of outPayloads are replaced with the list of parsed payloads.
      64              :      *
      65              :      * On failure, nothing should be assumed about the state of outPayloads.
      66              :      */
      67              :     CHIP_ERROR populatePayloads(std::vector<SetupPayload> & outPayloads) const;
      68              : 
      69              :     // TODO: ExtractPayload may need to change significantly.
      70              :     // See https://github.com/project-chip/connectedhomeip/issues/38731
      71              :     static std::string ExtractPayload(std::string inString);
      72              : 
      73              : private:
      74              :     static CHIP_ERROR retrieveOptionalInfos(SetupPayload & outPayload, TLV::ContiguousBufferTLVReader & reader);
      75              :     static CHIP_ERROR populateTLV(SetupPayload & outPayload, const std::vector<uint8_t> & buf, size_t & index);
      76              :     static CHIP_ERROR parseTLVFields(chip::SetupPayload & outPayload, uint8_t * tlvDataStart, size_t tlvDataLengthInBytes);
      77              : 
      78              :     static CHIP_ERROR populatePayloadFromBase38Data(std::string payload, SetupPayload & outPayload);
      79              : };
      80              : 
      81              : } // namespace chip
        

Generated by: LCOV version 2.0-1