QCBOR
Loading...
Searching...
No Matches
qcbor_main_encode.h
Go to the documentation of this file.
1/* ===========================================================================
2 * Copyright (c) 2016-2018, The Linux Foundation.
3 * Copyright (c) 2018-2024, Laurence Lundblade.
4 * Copyright (c) 2021, Arm Limited.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 * * Neither the name of The Linux Foundation nor the names of its
17 * contributors, nor the name "Laurence Lundblade" may be used to
18 * endorse or promote products derived from this software without
19 * specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
31 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ========================================================================= */
33
34#ifndef qcbor_main_encode_h
35#define qcbor_main_encode_h
36
37
38#include "qcbor/qcbor_common.h"
39#include "qcbor/qcbor_private.h"
40#include <stdbool.h>
41
42
43#ifdef __cplusplus
44extern "C" {
45#if 0
46} // Keep editor indention formatting happy
47#endif
48#endif
49
50
143#define QCBOR_HEAD_BUFFER_SIZE (sizeof(uint64_t) + 2)
144
145
146
300
301
302
303
311typedef struct _QCBOREncodeContext QCBOREncodeContext;
312
313
369void
371
372
393static void
395
396
408static void
410
411
412
413
452static void
454
456static void
457QCBOREncode_AddTextToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Text);
458
460static void
461QCBOREncode_AddTextToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Text);
462
463
472static void
473QCBOREncode_AddSZString(QCBOREncodeContext *pCtx, const char *szString);
474
476static void
477QCBOREncode_AddSZStringToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, const char *szString);
478
480static void
481QCBOREncode_AddSZStringToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, const char *szString);
482
483
497static void
499
501static void
502QCBOREncode_AddBytesToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Bytes);
503
505static void
506QCBOREncode_AddBytesToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Bytes);
507
508
540void
542
544static void
546 const char *szLabel,
547 UsefulBuf *pPlace);
548
550static void
552 int64_t nLabel,
553 UsefulBuf *pPlace);
554
555
570void
572
573
584static void
586
588static void
589QCBOREncode_AddBoolToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, bool b);
590
592static void
593QCBOREncode_AddBoolToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, bool b);
594
595
608static void
610
612static void
613QCBOREncode_AddNULLToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel);
614
616static void
617QCBOREncode_AddNULLToMapN(QCBOREncodeContext *pCtx, int64_t nLabel);
618
619
634static void
636
638static void
639QCBOREncode_AddUndefToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel);
640
642static void
644
645
664static void
665QCBOREncode_AddSimple(QCBOREncodeContext *pCtx, const uint8_t uNum);
666
668static void
670 const char *szLabel,
671 const uint8_t uSimple);
672
674static void
676 const int64_t nLabel,
677 const uint8_t uSimple);
678
679
713static void
715
717static void
718QCBOREncode_OpenArrayInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel);
719
721static void
723
724
746static void
748
749
750
751
783static void
785
787static void
788QCBOREncode_OpenMapInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel);
789
791static void
792QCBOREncode_OpenMapInMapN(QCBOREncodeContext *pCtx, int64_t nLabel);
793
794
815static void
817
818
829static void
831
833static void
835 const char *szLabel);
836
838static void
840 int64_t nLabel);
841
842
851static void
853
854
865static void
867
869static void
871 const char *szLabel);
872
874static void
876 int64_t nLabel);
877
878
879
880
889static void
891
892
913void
915
917void
919
920
953static void
955
957static void
958QCBOREncode_BstrWrapInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel);
959
961static void
963
964
1000void
1001QCBOREncode_CloseBstrWrap2(QCBOREncodeContext *pCtx, bool bIncludeCBORHead, UsefulBufC *pWrappedCBOR);
1002
1004static void
1006
1007
1024void
1026
1027
1046void
1048
1049
1051static void
1052QCBOREncode_AddEncodedToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Encoded);
1053
1055static void
1056QCBOREncode_AddEncodedToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Encoded);
1057
1058
1131
1132
1147
1148
1159static int
1161
1162
1174static UsefulBuf
1176
1177
1191static QCBORError
1193
1194
1227static size_t
1229
1230
1258QCBOREncode_SubString(QCBOREncodeContext *pCtx, const size_t uStart);
1259
1260
1297 uint8_t uMajorType,
1298 uint8_t uMinLen,
1299 uint64_t uNumber);
1300
1301
1302
1303
1304/* ========================================================================= *
1305 * BEGINNING OF DEPRECATED FUNCTION DECLARATIONS *
1306 * *
1307 * There is no plan to remove these in future versions. *
1308 * They just have been replaced by something better. *
1309 * ========================================================================= */
1310
1311
1313static void
1314QCBOREncode_AddTextToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Text);
1315
1317static void
1318QCBOREncode_AddSZStringToMap(QCBOREncodeContext *pCtx, const char *szLabel, const char *szString);
1319
1321static void
1322QCBOREncode_AddBytesToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Bytes);
1323
1325static void
1326QCBOREncode_AddBoolToMap(QCBOREncodeContext *pCtx, const char *szLabel, bool b);
1327
1329static void
1330QCBOREncode_AddNULLToMap(QCBOREncodeContext *pCtx, const char *szLabel);
1331
1333static void
1334QCBOREncode_AddUndefToMap(QCBOREncodeContext *pCtx, const char *szLabel);
1335
1337static void
1339 const char *szLabel,
1340 const uint8_t uSimple);
1341
1343static void
1344QCBOREncode_OpenArrayInMap(QCBOREncodeContext *pCtx, const char *szLabel);
1345
1347static void
1348QCBOREncode_OpenMapInMap(QCBOREncodeContext *pCtx, const char *szLabel);
1349
1351static void
1353 const char *szLabel);
1354
1356static void
1358 const char *szLabel);
1359
1361static void
1362QCBOREncode_BstrWrapInMap(QCBOREncodeContext *pCtx, const char *szLabel);
1363
1365static void
1366QCBOREncode_AddEncodedToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Encoded);
1367
1368
1369/* ========================================================================= *
1370 * END OF DEPRECATED FUNCTION DECLARATIONS *
1371 * ========================================================================= */
1372
1373
1374
1375
1376/* ========================================================================= *
1377 * BEGINNING OF PRIVATE INLINE IMPLEMENTATION *
1378 * ========================================================================= */
1379
1381void QCBOREncode_Private_AppendCBORHead(QCBOREncodeContext *pMe,
1382 const uint8_t uMajorType,
1383 const uint64_t uArgument,
1384 const uint8_t uMinLen);
1385
1387void
1388QCBOREncode_Private_AddBuffer(QCBOREncodeContext *pCtx,
1389 uint8_t uMajorType,
1390 UsefulBufC Bytes);
1391
1393void
1394QCBOREncode_Private_OpenMapOrArray(QCBOREncodeContext *pCtx,
1395 uint8_t uMajorType);
1396
1398void
1399QCBOREncode_Private_OpenMapOrArrayIndefiniteLength(QCBOREncodeContext *pCtx,
1400 uint8_t uMajorType);
1401
1403void
1404QCBOREncode_Private_CloseMapOrArray(QCBOREncodeContext *pCtx,
1405 uint8_t uMajorType);
1406
1408void
1409QCBOREncode_Private_CloseMapOrArrayIndefiniteLength(QCBOREncodeContext *pCtx,
1410 uint8_t uMajorType);
1411
1413void
1414QCBOREncode_Private_CloseMapUnsorted(QCBOREncodeContext *pMe);
1415
1417void
1418QCBOREncode_AddInt64(QCBOREncodeContext *pCtx, int64_t nNum);
1419
1420
1437static inline void
1438QCBOREncode_Private_AddType7(QCBOREncodeContext *pMe,
1439 const uint8_t uMinLen,
1440 const uint64_t uArgument)
1441{
1442 QCBOREncode_Private_AppendCBORHead(pMe, CBOR_MAJOR_TYPE_SIMPLE, uArgument, uMinLen);
1443}
1444
1445
1446
1447
1448static inline void
1450{
1451 /* The close function is made a function pointer as a way to avoid
1452 * linking the proportionately large chunk of code for sorting
1453 * maps unless explicitly requested. QCBOREncode_CloseAndSortMap()
1454 * doesn't get linked unless this function is called. */
1455 if(uConfig & QCBOR_ENCODE_CONFIG_SORT) {
1456 pMe->pfnCloseMap = QCBOREncode_CloseAndSortMap;
1457 } else {
1458 pMe->pfnCloseMap = QCBOREncode_Private_CloseMapUnsorted;
1459 }
1460 pMe->uConfigFlags = (int)uConfig;
1461}
1462
1463
1464static inline void
1466{
1467 if(uConfig & QCBOR_ENCODE_CONFIG_SORT) {
1468 pMe->uError = QCBOR_ERR_NOT_ALLOWED;
1469 } else {
1470 pMe->uConfigFlags = (int)uConfig;
1471 }
1472}
1473
1474
1475
1476static inline void
1478{
1479 QCBOREncode_Private_AddBuffer(pMe, CBOR_MAJOR_TYPE_TEXT_STRING, Text);
1480}
1481
1482static inline void
1484 const char *szLabel,
1485 const UsefulBufC Text)
1486{
1488 QCBOREncode_AddText(pMe, Text);
1489}
1490
1491static inline void
1493{
1494 QCBOREncode_AddTextToMapSZ(pMe, szLabel, Text);
1495}
1496
1497static inline void
1499 const int64_t nLabel,
1500 const UsefulBufC Text)
1501{
1502 QCBOREncode_AddInt64(pMe, nLabel);
1503 QCBOREncode_AddText(pMe, Text);
1504}
1505
1506
1507inline static void
1509{
1510 QCBOREncode_AddText(pMe, UsefulBuf_FromSZ(szString));
1511}
1512
1513static inline void
1515 const char *szLabel,
1516 const char *szString)
1517{
1518 QCBOREncode_AddSZString(pMe, szLabel);
1519 QCBOREncode_AddSZString(pMe, szString);
1520}
1521
1522static inline void
1523QCBOREncode_AddSZStringToMap(QCBOREncodeContext *pMe, const char *szLabel, const char *szString)
1524{
1525 QCBOREncode_AddSZStringToMapSZ(pMe, szLabel, szString);
1526}
1527
1528static inline void
1530 const int64_t nLabel,
1531 const char *szString)
1532{
1533 QCBOREncode_AddInt64(pMe, nLabel);
1534 QCBOREncode_AddSZString(pMe, szString);
1535}
1536
1537
1538
1539
1540static inline void
1542 const UsefulBufC Bytes)
1543{
1544 QCBOREncode_Private_AddBuffer(pMe, CBOR_MAJOR_TYPE_BYTE_STRING, Bytes);
1545}
1546
1547static inline void
1549 const char *szLabel,
1550 const UsefulBufC Bytes)
1551{
1552 QCBOREncode_AddSZString(pMe, szLabel);
1553 QCBOREncode_AddBytes(pMe, Bytes);
1554}
1555
1556static inline void
1558{
1559 QCBOREncode_AddBytesToMapSZ(pMe, szLabel, Bytes);
1560}
1561
1562static inline void
1564 const int64_t nLabel,
1565 const UsefulBufC Bytes)
1566{
1567 QCBOREncode_AddInt64(pMe, nLabel);
1568 QCBOREncode_AddBytes(pMe, Bytes);
1569}
1570
1571static inline void
1573 const char *szLabel,
1574 UsefulBuf *pPlace)
1575{
1576 QCBOREncode_AddSZString(pMe, szLabel);
1577 QCBOREncode_OpenBytes(pMe, pPlace);
1578}
1579
1580static inline void
1582 const int64_t nLabel,
1583 UsefulBuf *pPlace)
1584{
1585 QCBOREncode_AddInt64(pMe, nLabel);
1586 QCBOREncode_OpenBytes(pMe, pPlace);
1587}
1588
1589
1590static inline void
1592{
1593#ifndef QCBOR_DISABLE_ENCODE_USAGE_GUARDS
1594 if(pMe->uConfigFlags & QCBOR_ENCODE_CONFIG_ONLY_DCBOR_SIMPLE) {
1595 if(uNum < CBOR_SIMPLEV_FALSE || uNum > CBOR_SIMPLEV_NULL) {
1596 pMe->uError = QCBOR_ERR_NOT_PREFERRED;
1597 return;
1598 }
1599 }
1600 /* This check often is optimized out because uNum is known at compile time. */
1601 if(uNum >= CBOR_SIMPLEV_RESERVED_START && uNum <= CBOR_SIMPLEV_RESERVED_END) {
1602 pMe->uError = QCBOR_ERR_ENCODE_UNSUPPORTED;
1603 return;
1604 }
1605#endif /* ! QCBOR_DISABLE_ENCODE_USAGE_GUARDS */
1606
1607 QCBOREncode_Private_AddType7(pMe, 0, uNum);
1608}
1609
1610static inline void
1612 const char *szLabel,
1613 const uint8_t uSimple)
1614{
1615 QCBOREncode_AddSZString(pMe, szLabel);
1616 QCBOREncode_AddSimple(pMe, uSimple);
1617}
1618
1619static inline void
1621 const char *szLabel,
1622 const uint8_t uSimple)
1623{
1624 QCBOREncode_AddSimpleToMapSZ(pMe, szLabel, uSimple);
1625}
1626
1627static inline void
1629 const int64_t nLabel,
1630 const uint8_t uSimple)
1631{
1632 QCBOREncode_AddInt64(pMe, nLabel);
1633 QCBOREncode_AddSimple(pMe, uSimple);
1634}
1635
1636
1637static inline void
1639{
1640 uint8_t uSimple = CBOR_SIMPLEV_FALSE;
1641 if(b) {
1642 uSimple = CBOR_SIMPLEV_TRUE;
1643 }
1644 QCBOREncode_AddSimple(pMe, uSimple);
1645}
1646
1647static inline void
1648QCBOREncode_AddBoolToMapSZ(QCBOREncodeContext *pMe, const char *szLabel, const bool b)
1649{
1650 QCBOREncode_AddSZString(pMe, szLabel);
1651 QCBOREncode_AddBool(pMe, b);
1652}
1653
1654static inline void
1655QCBOREncode_AddBoolToMap(QCBOREncodeContext *pMe, const char *szLabel, bool b)
1656{
1657 QCBOREncode_AddBoolToMapSZ(pMe, szLabel, b);
1658}
1659
1660static inline void
1661QCBOREncode_AddBoolToMapN(QCBOREncodeContext *pMe, const int64_t nLabel, const bool b)
1662{
1663 QCBOREncode_AddInt64(pMe, nLabel);
1664 QCBOREncode_AddBool(pMe, b);
1665}
1666
1667
1668static inline void
1670{
1671 QCBOREncode_AddSimple(pMe, CBOR_SIMPLEV_NULL);
1672}
1673
1674static inline void
1676{
1677 QCBOREncode_AddSZString(pMe, szLabel);
1679}
1680
1681static inline void
1683{
1684 QCBOREncode_AddNULLToMapSZ(pMe, szLabel);
1685}
1686
1687static inline void
1689{
1690 QCBOREncode_AddInt64(pMe, nLabel);
1692}
1693
1694
1695static inline void
1697{
1698 QCBOREncode_AddSimple(pMe, CBOR_SIMPLEV_UNDEF);
1699}
1700
1701static inline void
1703{
1704 QCBOREncode_AddSZString(pMe, szLabel);
1706}
1707
1708static inline void
1710{
1711 QCBOREncode_AddUndefToMapSZ(pCtx, szLabel);
1712}
1713
1714static inline void
1716{
1717 QCBOREncode_AddInt64(pMe, nLabel);
1719}
1720
1721
1722static inline void
1724{
1725 QCBOREncode_Private_OpenMapOrArray(pMe, CBOR_MAJOR_TYPE_ARRAY);
1726}
1727
1728static inline void
1730{
1731 QCBOREncode_AddSZString(pMe, szLabel);
1733}
1734
1735static inline void
1737{
1738 QCBOREncode_OpenArrayInMapSZ(pMe, szLabel);
1739}
1740
1741
1742static inline void
1744{
1745 QCBOREncode_AddInt64(pMe, nLabel);
1747}
1748
1749
1750static inline void
1752{
1753 QCBOREncode_Private_CloseMapOrArray(pMe, CBOR_MAJOR_TYPE_ARRAY);
1754}
1755
1756
1757static inline void
1759{
1760 QCBOREncode_Private_OpenMapOrArray(pMe, CBOR_MAJOR_TYPE_MAP);
1761}
1762
1763static inline void
1765{
1766 QCBOREncode_AddSZString(pMe, szLabel);
1768}
1769
1770static inline void
1772{
1773 QCBOREncode_OpenMapInMapSZ(pMe, szLabel);
1774}
1775
1776static inline void
1778{
1779 QCBOREncode_AddInt64(pMe, nLabel);
1781}
1782
1783static inline void
1785{
1786 (pMe->pfnCloseMap)(pMe);
1787}
1788
1789static inline void
1791{
1792 QCBOREncode_Private_OpenMapOrArrayIndefiniteLength(pMe, CBOR_MAJOR_NONE_TYPE_ARRAY_INDEFINITE_LEN);
1793}
1794
1795static inline void
1802
1803static inline void
1809
1810static inline void
1812 const int64_t nLabel)
1813{
1814 QCBOREncode_AddInt64(pMe, nLabel);
1816}
1817
1818static inline void
1820{
1821 QCBOREncode_Private_CloseMapOrArrayIndefiniteLength(pMe, CBOR_MAJOR_NONE_TYPE_ARRAY_INDEFINITE_LEN);
1822}
1823
1824
1825static inline void
1827{
1828 QCBOREncode_Private_OpenMapOrArrayIndefiniteLength(pMe, CBOR_MAJOR_NONE_TYPE_MAP_INDEFINITE_LEN);
1829}
1830
1831static inline void
1838
1839static inline void
1845
1846static inline void
1848 const int64_t nLabel)
1849{
1850 QCBOREncode_AddInt64(pMe, nLabel);
1852}
1853
1854static inline void
1856{
1857 QCBOREncode_Private_CloseMapOrArrayIndefiniteLength(pMe, CBOR_MAJOR_NONE_TYPE_MAP_INDEFINITE_LEN);
1858}
1859
1860
1861static inline void
1863{
1864 QCBOREncode_Private_OpenMapOrArray(pMe, CBOR_MAJOR_TYPE_BYTE_STRING);
1865}
1866
1867static inline void
1869{
1870 QCBOREncode_AddSZString(pMe, szLabel);
1872}
1873
1874static inline void /* Deprecated */
1876{
1877 QCBOREncode_BstrWrapInMapSZ(pMe, szLabel);
1878}
1879
1880static inline void
1882{
1883 QCBOREncode_AddInt64(pMe, nLabel);
1885}
1886
1887static inline void
1889{
1890 QCBOREncode_CloseBstrWrap2(pMe, true, pWrappedCBOR);
1891}
1892
1893
1894
1895static inline void
1897 const char *szLabel,
1898 const UsefulBufC Encoded)
1899{
1900 QCBOREncode_AddSZString(pMe, szLabel);
1901 QCBOREncode_AddEncoded(pMe, Encoded);
1902}
1903
1904static inline void /* Deprecated */
1906{
1907 QCBOREncode_AddEncodedToMapSZ(pMe, szLabel, Encoded);
1908}
1909
1910static inline void
1912 const int64_t nLabel,
1913 const UsefulBufC Encoded)
1914{
1915 QCBOREncode_AddInt64(pMe, nLabel);
1916 QCBOREncode_AddEncoded(pMe, Encoded);
1917}
1918
1919
1920static inline int
1922{
1923 return UsefulOutBuf_IsBufferNULL(&(pMe->OutBuf));
1924}
1925
1926
1927static inline UsefulBuf
1932
1933
1934static inline QCBORError
1936{
1937 if(UsefulOutBuf_GetError(&(pMe->OutBuf))) {
1938 /* Items didn't fit in the buffer. This check catches this
1939 * condition for all the appends and inserts so checks aren't
1940 * needed when the appends and inserts are performed. And of
1941 * course UsefulBuf will never overrun the input buffer given to
1942 * it. No complex analysis of the error handling in this file is
1943 * needed to know that is true. Just read the UsefulBuf code.
1944 */
1945 pMe->uError = QCBOR_ERR_BUFFER_TOO_SMALL;
1946 /* QCBOR_ERR_BUFFER_TOO_SMALL masks other errors, but that is
1947 * OK. Once the caller fixes this, they'll be unmasked.
1948 */
1949 }
1950
1951 return (QCBORError)pMe->uError;
1952}
1953
1954
1955static inline size_t
1957{
1958 return UsefulOutBuf_GetEndPosition(&(pMe->OutBuf));
1959}
1960
1961
1962/* ======================================================================== *
1963 * END OF PRIVATE INLINE IMPLEMENTATION *
1964 * ======================================================================== */
1965
1966
1967#ifdef __cplusplus
1968}
1969#endif
1970
1971#endif /* qcbor_encode_h */
static size_t UsefulOutBuf_GetEndPosition(UsefulOutBuf *pUOutBuf)
Returns position of end of data in the UsefulOutBuf.
Definition UsefulBuf.h:2138
static UsefulBufC UsefulBuf_FromSZ(const char *szString)
Convert a NULL-terminated string to a UsefulBufC.
Definition UsefulBuf.h:1995
static UsefulBuf UsefulOutBuf_RetrieveOutputStorage(UsefulOutBuf *pUOutBuf)
Retrieve the storage buffer passed in to UsefulOutBuf_Init().
Definition UsefulBuf.h:2434
static int UsefulOutBuf_IsBufferNULL(UsefulOutBuf *pUOutBuf)
Returns 1 if buffer given to UsefulOutBuf_Init() was NULL.
Definition UsefulBuf.h:2413
static int UsefulOutBuf_GetError(UsefulOutBuf *pUOutBuf)
Returns the current error status.
Definition UsefulBuf.h:2395
QCBORError
Definition qcbor_common.h:260
@ QCBOR_ERR_NOT_PREFERRED
Definition qcbor_common.h:554
@ QCBOR_ERR_NOT_ALLOWED
Definition qcbor_common.h:557
@ QCBOR_ERR_ENCODE_UNSUPPORTED
Definition qcbor_common.h:270
@ QCBOR_ERR_BUFFER_TOO_SMALL
Definition qcbor_common.h:266
QCBORError QCBOREncode_FinishGetSize(QCBOREncodeContext *pCtx, size_t *uEncodedLen)
Get the encoded CBOR and error status.
static void QCBOREncode_OpenMapInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1777
static void QCBOREncode_OpenMapInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1771
struct _QCBOREncodeContext QCBOREncodeContext
Definition qcbor_main_encode.h:311
static void QCBOREncode_AddUndefToMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1709
static void QCBOREncode_OpenArrayIndefiniteLengthInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1811
static void QCBOREncode_AddNULLToMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1682
static void QCBOREncode_OpenArray(QCBOREncodeContext *pCtx)
Indicates that the next items added are in an array.
Definition qcbor_main_encode.h:1723
static void QCBOREncode_AddEncodedToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Encoded)
Definition qcbor_main_encode.h:1911
UsefulBufC QCBOREncode_EncodeHead(UsefulBuf Buffer, uint8_t uMajorType, uint8_t uMinLen, uint64_t uNumber)
Encode the head of a CBOR data item.
static void QCBOREncode_AddSimpleToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, const uint8_t uSimple)
Definition qcbor_main_encode.h:1611
static void QCBOREncode_AddBoolToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, bool b)
Definition qcbor_main_encode.h:1661
static void QCBOREncode_OpenMapIndefiniteLength(QCBOREncodeContext *pCtx)
Indicates that the next items added are in an indefinite length map.
Definition qcbor_main_encode.h:1826
static void QCBOREncode_OpenArrayIndefiniteLengthInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1804
QCBOREncodeConfig
Definition qcbor_main_encode.h:151
@ QCBOR_ENCODE_CONFIG_PREFERRED
Definition qcbor_main_encode.h:240
@ QCBOR_ENCODE_CONFIG_DISALLOW_INDEFINITE_LENGTHS
Definition qcbor_main_encode.h:192
@ QCBOR_ENCODE_CONFIG_SORT
Definition qcbor_main_encode.h:164
@ QCBOR_ENCODE_CONFIG_ONLY_DCBOR_SIMPLE
Definition qcbor_main_encode.h:205
@ QCBOR_ENCODE_CONFIG_CDE
Definition qcbor_main_encode.h:261
@ QCBOR_ENCODE_CONFIG_DCBOR
Definition qcbor_main_encode.h:296
@ QCBOR_ENCODE_CONFIG_DISALLOW_NON_PREFERRED_NUMBERS
Definition qcbor_main_encode.h:198
@ QCBOR_ENCODE_CONFIG_ALLOW_NAN_PAYLOAD
Definition qcbor_main_encode.h:171
@ QCBOR_ENCODE_CONFIG_FLOAT_REDUCTION
Definition qcbor_main_encode.h:188
@ QCBOR_ENCODE_CONFIG_ONLY_PREFERRED_BIG_NUMBERS
Definition qcbor_main_encode.h:212
static void QCBOREncode_OpenArrayIndefiniteLength(QCBOREncodeContext *pCtx)
Indicates that the next items added are in an indefinite length array.
Definition qcbor_main_encode.h:1790
static void QCBOREncode_OpenArrayInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1743
static void QCBOREncode_AddUndefToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1702
static void QCBOREncode_AddBytesToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Bytes)
Definition qcbor_main_encode.h:1563
void QCBOREncode_AddEncoded(QCBOREncodeContext *pCtx, UsefulBufC Encoded)
Add some already-encoded CBOR bytes.
static void QCBOREncode_BstrWrapInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1881
static void QCBOREncode_AddBool(QCBOREncodeContext *pCtx, bool b)
Add a standard Boolean.
Definition qcbor_main_encode.h:1638
static void QCBOREncode_OpenBytesInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBuf *pPlace)
Definition qcbor_main_encode.h:1572
void QCBOREncode_CancelBstrWrap(QCBOREncodeContext *pCtx)
Cancel byte string wrapping.
static void QCBOREncode_OpenMapInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1764
static void QCBOREncode_AddEncodedToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Encoded)
Definition qcbor_main_encode.h:1896
static QCBORError QCBOREncode_GetErrorState(QCBOREncodeContext *pCtx)
Get the encoding error state.
Definition qcbor_main_encode.h:1935
void QCBOREncode_CloseBytes(QCBOREncodeContext *pCtx, size_t uAmount)
Close out a byte string written directly to encoded output.
static void QCBOREncode_OpenArrayIndefiniteLengthInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1796
static void QCBOREncode_AddTextToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Text)
Definition qcbor_main_encode.h:1483
void QCBOREncode_CloseAndSortMap(QCBOREncodeContext *pCtx)
Close and sort an open map.
static void QCBOREncode_OpenMapIndefiniteLengthInMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1847
static void QCBOREncode_AddSimple(QCBOREncodeContext *pCtx, const uint8_t uNum)
Add a simple value.
Definition qcbor_main_encode.h:1591
static void QCBOREncode_AddSZStringToMap(QCBOREncodeContext *pCtx, const char *szLabel, const char *szString)
Definition qcbor_main_encode.h:1523
static void QCBOREncode_AddSimpleToMap(QCBOREncodeContext *pCtx, const char *szLabel, const uint8_t uSimple)
Definition qcbor_main_encode.h:1620
static void QCBOREncode_AddBoolToMap(QCBOREncodeContext *pCtx, const char *szLabel, bool b)
Definition qcbor_main_encode.h:1655
static void QCBOREncode_OpenBytesInMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBuf *pPlace)
Definition qcbor_main_encode.h:1581
static void QCBOREncode_BstrWrapInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1875
static void QCBOREncode_CloseBstrWrap(QCBOREncodeContext *pCtx, UsefulBufC *pWrappedCBOR)
Definition qcbor_main_encode.h:1888
static void QCBOREncode_CloseMap(QCBOREncodeContext *pCtx)
Close an open map.
Definition qcbor_main_encode.h:1784
UsefulBufC QCBOREncode_SubString(QCBOREncodeContext *pCtx, const size_t uStart)
Get a substring of encoded CBOR for cryptographic hash.
static size_t QCBOREncode_Tell(QCBOREncodeContext *pCtx)
Returns current end of encoded data.
Definition qcbor_main_encode.h:1956
static void QCBOREncode_CloseMapIndefiniteLength(QCBOREncodeContext *pCtx)
Close an open indefinite length map.
Definition qcbor_main_encode.h:1855
static void QCBOREncode_AddNULLToMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1688
static void QCBOREncode_AddSZStringToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, const char *szString)
Definition qcbor_main_encode.h:1529
static void QCBOREncode_BstrWrap(QCBOREncodeContext *pCtx)
Indicate start of encoded CBOR to be wrapped in a bstr.
Definition qcbor_main_encode.h:1862
static void QCBOREncode_AddEncodedToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Encoded)
Definition qcbor_main_encode.h:1905
static void QCBOREncode_CloseArray(QCBOREncodeContext *pCtx)
Close an open array.
Definition qcbor_main_encode.h:1751
static void QCBOREncode_AddSZStringToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, const char *szString)
Definition qcbor_main_encode.h:1514
static void QCBOREncode_ConfigReduced(QCBOREncodeContext *pCtx, enum QCBOREncodeConfig uConfig)
Configure the encoder, reduced object code.
Definition qcbor_main_encode.h:1465
static void QCBOREncode_AddUndef(QCBOREncodeContext *pCtx)
Add an "undef" to the encoded output.
Definition qcbor_main_encode.h:1696
static void QCBOREncode_AddBytesToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Bytes)
Definition qcbor_main_encode.h:1557
static void QCBOREncode_AddText(QCBOREncodeContext *pCtx, UsefulBufC Text)
Add a UTF-8 text string to the encoded output.
Definition qcbor_main_encode.h:1477
static void QCBOREncode_Config(QCBOREncodeContext *pCtx, enum QCBOREncodeConfig uConfig)
Configure the encoder.
Definition qcbor_main_encode.h:1449
static void QCBOREncode_OpenMapIndefiniteLengthInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1832
static void QCBOREncode_AddUndefToMapN(QCBOREncodeContext *pCtx, int64_t nLabel)
Definition qcbor_main_encode.h:1715
static void QCBOREncode_AddBoolToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, bool b)
Definition qcbor_main_encode.h:1648
static void QCBOREncode_AddBytes(QCBOREncodeContext *pCtx, UsefulBufC Bytes)
Add a byte string to the encoded output.
Definition qcbor_main_encode.h:1541
void QCBOREncode_Init(QCBOREncodeContext *pCtx, UsefulBuf Storage)
static UsefulBuf QCBOREncode_RetrieveOutputStorage(QCBOREncodeContext *pCtx)
Retrieve the storage buffer passed in to QCBOREncode_Init().
Definition qcbor_main_encode.h:1928
static void QCBOREncode_OpenMapIndefiniteLengthInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1840
static void QCBOREncode_CloseArrayIndefiniteLength(QCBOREncodeContext *pCtx)
Close an open indefinite length array.
Definition qcbor_main_encode.h:1819
QCBORError QCBOREncode_Finish(QCBOREncodeContext *pCtx, UsefulBufC *pEncodedCBOR)
Get the encoded result.
static void QCBOREncode_AddTextToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, UsefulBufC Text)
Definition qcbor_main_encode.h:1498
void QCBOREncode_CloseAndSortMapIndef(QCBOREncodeContext *pCtx)
static void QCBOREncode_AddSZString(QCBOREncodeContext *pCtx, const char *szString)
Add a UTF-8 text string to the encoded output.
Definition qcbor_main_encode.h:1508
static void QCBOREncode_OpenArrayInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1729
static void QCBOREncode_OpenArrayInMap(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1736
void QCBOREncode_OpenBytes(QCBOREncodeContext *pCtx, UsefulBuf *pPlace)
Set up to write a byte string value directly to encoded output.
static int QCBOREncode_IsBufferNULL(QCBOREncodeContext *pCtx)
Indicate whether the output storage buffer is NULL.
Definition qcbor_main_encode.h:1921
static void QCBOREncode_AddNULLToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1675
static void QCBOREncode_AddBytesToMapSZ(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Bytes)
Definition qcbor_main_encode.h:1548
static void QCBOREncode_OpenMap(QCBOREncodeContext *pCtx)
Indicates that the next items added are in a map.
Definition qcbor_main_encode.h:1758
void QCBOREncode_CloseBstrWrap2(QCBOREncodeContext *pCtx, bool bIncludeCBORHead, UsefulBufC *pWrappedCBOR)
Close a wrapping bstr.
static void QCBOREncode_AddTextToMap(QCBOREncodeContext *pCtx, const char *szLabel, UsefulBufC Text)
Definition qcbor_main_encode.h:1492
static void QCBOREncode_AddNULL(QCBOREncodeContext *pCtx)
Add a NULL to the encoded output.
Definition qcbor_main_encode.h:1669
static void QCBOREncode_AddSimpleToMapN(QCBOREncodeContext *pCtx, const int64_t nLabel, const uint8_t uSimple)
Definition qcbor_main_encode.h:1628
static void QCBOREncode_BstrWrapInMapSZ(QCBOREncodeContext *pCtx, const char *szLabel)
Definition qcbor_main_encode.h:1868
Definition UsefulBuf.h:280
Definition UsefulBuf.h:291