Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / setup_payload / QRCodeSetupPayloadGenerator.h
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 generator based on the
21  *      CHIP specification.
22  *
23  *      The encoding of the binary data to a base41 string is as follows:
24  *      - Every 2 bytes (16 bits) of binary source data are encoded to 3
25  *        characters of the Base-41 alphabet.
26  *      - If an odd number of bytes are to be encoded, the remaining
27  *        single byte is encoded to 2 characters of the Base-41 alphabet.
28  */
29
30 #include "SetupPayload.h"
31
32 #include <string>
33
34 #pragma once
35
36 namespace chip {
37
38 class QRCodeSetupPayloadGenerator
39 {
40 private:
41     SetupPayload mPayload;
42
43 public:
44     QRCodeSetupPayloadGenerator(const SetupPayload & setupPayload) : mPayload(setupPayload) {}
45
46     /**
47      * This function is called to encode the binary data of a payload to a
48      * base41 string using CHIP TLV encoding scheme.
49      *
50      * @param[out] base41Representation
51      *                  The string to copy the base41 to.
52      *
53      * @retval #CHIP_NO_ERROR if the method succeeded.
54      * @retval #CHIP_ERROR_INVALID_ARGUMENT if the payload is invalid.
55      * @retval other Other CHIP or platform-specific error codes indicating
56      *               that an error occurred preventing the function from
57      *               producing the requested string.
58      */
59     CHIP_ERROR payloadBase41Representation(std::string & base41Representation);
60
61     /**
62      * This function is called to encode the binary data of a payload to a
63      * base41 string. Callers must pass a buffer of at least
64      * chip::kTotalPayloadDataInBytes or more if there is any serialNumber or
65      * any other optional data. The buffer should be big enough to hold the
66      * TLV encoded value of the payload. If not an error will be throw.
67      *
68      * @param[out] base41Representation
69      *                  The string to copy the base41 to.
70      * @param[in]  tlvDataStart
71      *                  A pointer to an uint8_t buffer into which the TLV
72      *                  should be written.
73      * @param[in]  tlvDataStartSize
74      *                  The maximum number of bytes that should be written to
75      *                  the output buffer.
76      *
77      * @retval #CHIP_NO_ERROR if the method succeeded.
78      * @retval #CHIP_ERROR_INVALID_ARGUMENT if the payload is invalid.
79      * @retval other Other CHIP or platform-specific error codes indicating
80      *               that an error occurred preventing the function from
81      *               producing the requested string.
82      */
83     CHIP_ERROR payloadBase41Representation(std::string & base41Representation, uint8_t * tlvDataStart, uint32_t tlvDataStartSize);
84
85 private:
86     CHIP_ERROR generateTLVFromOptionalData(SetupPayload & outPayload, uint8_t * tlvDataStart, uint32_t maxLen,
87                                            size_t & tlvDataLengthInBytes);
88 };
89
90 } // namespace chip