Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/cborvalidation.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
</tr>
<tr>
<td>1</td>
<td>integer</td>
<td>numeric (integer or floating-point)</td>
<td>Epoch-based date/time</td>
</tr>
<tr>
Expand Down Expand Up @@ -169,17 +169,17 @@
</tr>
<tr>
<td>21</td>
<td>byte string, array, map</td>
<td>any</td>
<td>Expected conversion to base64url encoding</td>
</tr>
<tr>
<td>22</td>
<td>byte string, array, map</td>
<td>any</td>
<td>Expected conversion to base64 encoding</td>
</tr>
<tr>
<td>23</td>
<td>byte string, array, map</td>
<td>any</td>
<td>Expected conversion to base16 encoding</td>
</tr>
<tr>
Expand Down Expand Up @@ -238,17 +238,18 @@
struct KnownTagData { uint32_t tag; uint32_t types; };
static const struct KnownTagData knownTagData[] = {
{ 0, (uint32_t)CborTextStringType },
{ 1, (uint32_t)(CborIntegerType+1) },
{ 1, (uint32_t)(CborIntegerType+1) | ((uint32_t)CborHalfFloatType << 8) |
((uint32_t)CborFloatType << 16) | ((uint32_t)CborDoubleType << 24)},
Comment thread
thiagomacieira marked this conversation as resolved.
{ 2, (uint32_t)CborByteStringType },
{ 3, (uint32_t)CborByteStringType },
{ 4, (uint32_t)CborArrayType },
{ 5, (uint32_t)CborArrayType },
{ 16, (uint32_t)CborArrayType },
{ 17, (uint32_t)CborArrayType },
{ 18, (uint32_t)CborArrayType },
{ 21, (uint32_t)CborByteStringType | ((uint32_t)CborArrayType << 8) | ((uint32_t)CborMapType << 16) },
{ 22, (uint32_t)CborByteStringType | ((uint32_t)CborArrayType << 8) | ((uint32_t)CborMapType << 16) },
{ 23, (uint32_t)CborByteStringType | ((uint32_t)CborArrayType << 8) | ((uint32_t)CborMapType << 16) },
{ 21, 0U /* any type allowed */ },
{ 22, 0U /* any type allowed */ },
{ 23, 0U /* any type allowed */ },
Comment thread
thiagomacieira marked this conversation as resolved.
{ 24, (uint32_t)CborByteStringType },
{ 32, (uint32_t)CborTextStringType },
{ 33, (uint32_t)CborTextStringType },
Expand Down
65 changes: 36 additions & 29 deletions tests/parser/tst_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,13 +1679,45 @@ void tst_Parser::strictValidation_data()
QTest::newRow("nonunique-content-map-SS") << raw("\xa2\x61z\1\x61z\2") << int(CborValidateStrictMode) << CborErrorMapKeysNotUnique;
QTest::newRow("nonunique-content-map-AA") << raw("\xa2\x81\x65Hello\1\x81\x65Hello\2") << int(CborValidateStrictMode) << CborErrorMapKeysNotUnique;

auto addTagAnyAllowed = [](int tagnumber, const QByteArray &tag) {
auto addRow = [&](const char *name, const QByteArray &payload) {
QTest::addRow("tag-%d-%s", tagnumber, name)
<< (tag + payload) << int(CborValidateStrictMode) << CborNoError;
};
addRow("unsigned", raw("\0"));
addRow("negative", "\x20");
addRow("bytearray", "\x40");
addRow("string", "\x60");
addRow("array", "\x80");
addRow("map", "\xa0");
QTest::addRow("tag-%d-tag-0-unsigned", tagnumber)
<< (tag + raw("\xc0\x00")) << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
addRow("tag-0-string", raw("\xc0\x60"));
addRow("simple0", raw("\xe0"));
addRow("false", raw("\xf4"));
addRow("true", raw("\xf5"));
addRow("null", raw("\xf6"));
addRow("undefined", raw("\xf7"));
addRow("simple32", raw("\xf8\x20"));
addRow("half", raw("\xf9\0\0"));
addRow("float", raw("\xfa\0\0\0\0"));
addRow("double", raw("\xfb\0\0\0\0\0\0\0\0"));
};
QTest::newRow("tag-0-unsigned") << raw("\xc0\x00") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-0-bytearray") << raw("\xc0\x40") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-0-string") << raw("\xc0\x60") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-0-tag-0-string") << raw("\xc0\xc0\x60") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-1-unsigned") << raw("\xc1\x00") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-1-negative") << raw("\xc1\x20") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-1-bytearray") << raw("\xc1\x40") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-1-string") << raw("\xc1\x60") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-1-array") << raw("\xc1\x80") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-1-map") << raw("\xc1\xa0") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-1-tag-unsigned") << raw("\xc1\xc1\x00") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-1-boolean") << raw("\xc1\xf4") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-1-fp16") << raw("\xc1\xf9\0\0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-1-float") << raw("\xc1\xfa\0\0\0\0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-1-double") << raw("\xc1\xfb\0\0\0\0\0\0\0\0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-2-bytearray") << raw("\xc2\x40") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-2-string") << raw("\xc2\x60") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-3-bytearray") << raw("\xc3\x40") << int(CborValidateStrictMode) << CborNoError;
Expand All @@ -1694,18 +1726,9 @@ void tst_Parser::strictValidation_data()
QTest::newRow("tag-4-array") << raw("\xc4\x82\0\1") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-5-string") << raw("\xc5\x60") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-5-array") << raw("\xc5\x82\0\1") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-21-bytearray") << raw("\xd5\x40") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-21-string") << raw("\xd5\x60") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-21-array") << raw("\xd5\x80") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-21-map") << raw("\xd5\xa0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-22-bytearray") << raw("\xd6\x40") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-22-string") << raw("\xd6\x60") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-22-array") << raw("\xd6\x80") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-22-map") << raw("\xd6\xa0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-23-bytearray") << raw("\xd7\x40") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-23-string") << raw("\xd7\x60") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-23-array") << raw("\xd7\x80") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-23-map") << raw("\xd7\xa0") << int(CborValidateStrictMode) << CborNoError;
addTagAnyAllowed(CborExpectedBase64urlTag, "\xd5");
addTagAnyAllowed(CborExpectedBase64Tag, "\xd6");
addTagAnyAllowed(CborExpectedBase16Tag, "\xd7");
QTest::newRow("tag-24-bytearray") << raw("\xd8\x18\x40") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-24-string") << raw("\xd8\x18\x60") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-32-bytearray") << raw("\xd8\x20\x40") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
Expand All @@ -1718,23 +1741,7 @@ void tst_Parser::strictValidation_data()
QTest::newRow("tag-35-string") << raw("\xd8\x23\x60") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-36-bytearray") << raw("\xd8\x24\x40") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-36-string") << raw("\xd8\x24\x60") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-unsigned") << raw("\xd9\xd9\xf7\x00") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-negative") << raw("\xd9\xd9\xf7\x20") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-bytearray") << raw("\xd9\xd9\xf7\x40") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-string") << raw("\xd9\xd9\xf7\x60") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-array") << raw("\xd9\xd9\xf7\x80") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-map") << raw("\xd9\xd9\xf7\xa0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-tag-0-unsigned") << raw("\xd9\xd9\xf7\xc0\x00") << int(CborValidateStrictMode) << CborErrorInappropriateTagForType;
QTest::newRow("tag-55799-tag-0-string") << raw("\xd9\xd9\xf7\xc0\x60") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-simple0") << raw("\xd9\xd9\xf7\xe0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-false") << raw("\xd9\xd9\xf7\xf4") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-true") << raw("\xd9\xd9\xf7\xf5") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-null") << raw("\xd9\xd9\xf7\xf6") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-undefined") << raw("\xd9\xd9\xf7\xf7") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-simple32") << raw("\xd9\xd9\xf7\xf8\x20") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-half") << raw("\xd9\xd9\xf7\xf9\0\0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-float") << raw("\xd9\xd9\xf7\xfa\0\0\0\0") << int(CborValidateStrictMode) << CborNoError;
QTest::newRow("tag-55799-double") << raw("\xd9\xd9\xf7\xfb\0\0\0\0\0\0\0\0") << int(CborValidateStrictMode) << CborNoError;
addTagAnyAllowed(CborSignatureTag, raw("\xd9\xd9\xf7"));

// excluded non-finite
QTest::newRow("excluded-fp-nan") << raw("\xfb\x7f\xf8\0\0\0\0\0\0") << int(CborValidateFiniteFloatingPoint) << CborErrorExcludedValue;
Expand Down
Loading