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 0 : QRCodeSetupPayloadParser(std::string base38Representation) : mBase38Representation(std::move(base38Representation)) {}
47 : CHIP_ERROR populatePayload(SetupPayload & outPayload);
48 : static std::string ExtractPayload(std::string inString);
49 :
50 : private:
51 : CHIP_ERROR retrieveOptionalInfos(SetupPayload & outPayload, TLV::ContiguousBufferTLVReader & reader);
52 : CHIP_ERROR populateTLV(SetupPayload & outPayload, const std::vector<uint8_t> & buf, size_t & index);
53 : CHIP_ERROR parseTLVFields(chip::SetupPayload & outPayload, uint8_t * tlvDataStart, size_t tlvDataLengthInBytes);
54 : };
55 :
56 : } // namespace chip
|