}
[Theory]
+ [InlineData(CborConformanceLevel.Lax, "bfff")]
+ [InlineData(CborConformanceLevel.Strict, "bfff")]
+ internal static void ReadMap_IndefiniteLength_SupportedConformanceLevel_ShouldSucceed(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ uint? length = reader.ReadStartMap();
+ Assert.Null(length);
+ }
+
+ [Theory]
+ [InlineData(CborConformanceLevel.Rfc7049Canonical, "bfff")]
+ [InlineData(CborConformanceLevel.Ctap2Canonical, "bfff")]
+ internal static void ReadMap_IndefiniteLength_UnSupportedConformanceLevel_ShouldThrowFormatException(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ Assert.Throws<FormatException>(() => reader.ReadStartMap());
+ Assert.Equal(0, reader.BytesRead);
+ }
+
+ [Theory]
[InlineData(CborConformanceLevel.Lax, "b800")]
[InlineData(CborConformanceLevel.Lax, "b90000")]
[InlineData(CborConformanceLevel.Lax, "ba00000000")]
[InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { Map, 1, 1, 2, 2, 3, 3 }, "a3010102020303")]
[InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { Map, 1, 1, 2, 2, 3, 3 }, "a3010102020303")]
// indefinite length string payload
- [InlineData(CborConformanceLevel.Lax, new object[] { Map, "b", 0, 2, 0, "a", 0, new string[] { "c", "" }, 0, 1, 0 }, "a561620002006161007f616360ff000100")]
- [InlineData(CborConformanceLevel.Strict, new object[] { Map, "b", 0, 2, 0, "a", 0, new string[] { "c", "" }, 0, 1, 0 }, "a561620002006161007f616360ff000100")]
- [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { Map, 1, 0, 2, 0, "a", 0, "b", 0, new string[] { "c", "" }, 0 }, "a5010002006161006162007f616360ff00")]
- [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { Map, 1, 0, 2, 0, "a", 0, "b", 0, new string[] { "c", "" }, 0 }, "a5010002006161006162007f616360ff00")]
+ [InlineData(CborConformanceLevel.Lax, new object[] { Map, "b", 0, 2, 0, "a", 0, new object[] { "c", "" }, 0, 1, 0 }, "a5616200020061610082616360000100")]
+ [InlineData(CborConformanceLevel.Strict, new object[] { Map, "b", 0, 2, 0, "a", 0, new object[] { "c", "" }, 0, 1, 0 }, "a5616200020061610082616360000100")]
+ [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { Map, 1, 0, 2, 0, "a", 0, "b", 0, new object[] { "c", "" }, 0 }, "a5010002006161006162008261636000")]
+ [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { Map, 1, 0, 2, 0, "a", 0, "b", 0, new object[] { "c", "" }, 0 }, "a5010002006161006162008261636000")]
// CBOR sorting rules do not match canonical string sorting
[InlineData(CborConformanceLevel.Lax, new object[] { Map, "aa", 0, "z", 0 }, "a262616100617a00")]
[InlineData(CborConformanceLevel.Strict, new object[] { Map, "aa", 0, "z", 0 }, "a262616100617a00")]
}
[Theory]
- [InlineData(CborConformanceLevel.Lax, new object[] { Map, 3, 3, 2, 2, 1, 1 }, "bf030302020101ff")]
- [InlineData(CborConformanceLevel.Strict, new object[] { Map, 3, 3, 2, 2, 1, 1 }, "bf030302020101ff")]
- [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { Map, 1, 1, 2, 2, 3, 3 }, "bf010102020303ff")]
- [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { Map, 1, 1, 2, 2, 3, 3 }, "bf010102020303ff")]
- // indefinite length string payload
- [InlineData(CborConformanceLevel.Lax, new object[] { Map, "b", 0, 2, 0, "a", 0, new string[] { "c", "" }, 0, 1, 0 }, "bf61620002006161007f616360ff000100ff")]
- [InlineData(CborConformanceLevel.Strict, new object[] { Map, "b", 0, 2, 0, "a", 0, new string[] { "c", "" }, 0, 1, 0 }, "bf61620002006161007f616360ff000100ff")]
- [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { Map, 1, 0, 2, 0, "a", 0, "b", 0, new string[] { "c", "" }, 0 }, "bf010002006161006162007f616360ff00ff")]
- [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { Map, 1, 0, 2, 0, "a", 0, "b", 0, new string[] { "c", "" }, 0 }, "bf010002006161006162007f616360ff00ff")]
- // CBOR sorting rules do not match canonical string sorting
- [InlineData(CborConformanceLevel.Lax, new object[] { Map, "aa", 0, "z", 0 }, "bf62616100617a00ff")]
- [InlineData(CborConformanceLevel.Strict, new object[] { Map, "aa", 0, "z", 0 }, "bf62616100617a00ff")]
- [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { Map, "z", 0, "aa", 0 }, "bf617a0062616100ff")]
- [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { Map, "z", 0, "aa", 0 }, "bf617a0062616100ff")]
- // Test case distinguishing between RFC7049 and CTAP2 sorting rules
- [InlineData(CborConformanceLevel.Lax, new object[] { Map, "", 0, 255, 0 }, "bf600018ff00ff")]
- [InlineData(CborConformanceLevel.Strict, new object[] { Map, "", 0, 255, 0 }, "bf600018ff00ff")]
- [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { Map, "", 0, 255, 0 }, "bf600018ff00ff")]
- [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { Map, 255, 0, "", 0 }, "bf18ff006000ff")]
- internal static void ReadMap_SimpleValues_IndefiniteLength_ShouldAcceptKeysSortedAccordingToConformanceLevel(CborConformanceLevel level, object expectedValue, string hexEncoding)
- {
- byte[] encoding = hexEncoding.HexToByteArray();
- var reader = new CborReader(encoding, level);
- Helpers.VerifyValue(reader, expectedValue, expectDefiniteLengthCollections: false);
- }
-
- [Theory]
- [InlineData(CborConformanceLevel.Lax, new object[] { Map, -1, 0, new object[] { Map, 3, 3, 2, 2, 1, 1 }, 0, "a", 0, 256, 0 }, "bf2000bf030302020101ff0061610019010000ff")]
- [InlineData(CborConformanceLevel.Strict, new object[] { Map, -1, 0, new object[] { Map, 3, 3, 2, 2, 1, 1 }, 0, "a", 0, 256, 0 }, "bf2000bf030302020101ff0061610019010000ff")]
- [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { Map, -1, 0, "a", 0, 256, 0, new object[] { Map, 1, 1, 2, 2, 3, 3 }, 0 }, "bf200061610019010000bf010102020303ff00ff")]
- [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { Map, 256, 0, -1, 0, "a", 0, new object[] { Map, 1, 1, 2, 2, 3, 3 }, 0 }, "bf190100002000616100bf010102020303ff00ff")]
- internal static void ReadMap_NestedValues_IndefiniteLength_ShouldAcceptKeysSortedAccordingToConformanceLevel(CborConformanceLevel level, object expectedValue, string hexEncoding)
- {
- byte[] encoding = hexEncoding.HexToByteArray();
- var reader = new CborReader(encoding, level);
- Helpers.VerifyValue(reader, expectedValue, expectDefiniteLengthCollections: false);
- }
-
- [Theory]
[InlineData(new object[] { Map, "a", 1, "a", 2 }, "a2616101616102")]
public static void ReadMap_DuplicateKeys_ShouldSucceed(object[] values, string hexEncoding)
{
[InlineData(CborConformanceLevel.Strict, "foobar", "a266666f6f6261720166666f6f62617202")]
[InlineData(CborConformanceLevel.Rfc7049Canonical, "foobar", "a266666f6f6261720166666f6f62617202")]
[InlineData(CborConformanceLevel.Ctap2Canonical, "foobar", "a266666f6f6261720166666f6f62617202")]
- [InlineData(CborConformanceLevel.Strict, new object[] { new string[] { "x", "y" } }, "a2817f61786179ff01817f61786179ff02")]
- [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { new string[] { "x", "y" } }, "a2817f61786179ff01817f61786179ff02")]
- [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { new string[] { "x", "y" } }, "a2817f61786179ff01817f61786179ff02")]
+ [InlineData(CborConformanceLevel.Strict, new object[] { new object[] { "x", "y" } }, "a28182617861790181826178617902")]
+ [InlineData(CborConformanceLevel.Rfc7049Canonical, new object[] { new object[] { "x", "y" } }, "a28182617861790181826178617902")]
+ [InlineData(CborConformanceLevel.Ctap2Canonical, new object[] { new object[] { "x", "y" } }, "a28182617861790181826178617902")]
internal static void ReadMap_DuplicateKeys_StrictConformance_ShouldThrowFormatException(CborConformanceLevel level, object dupeKey, string hexEncoding)
{
var reader = new CborReader(hexEncoding.HexToByteArray(), level);
}
[Theory]
+ [InlineData(CborConformanceLevel.Lax, "5f40ff")]
+ [InlineData(CborConformanceLevel.Strict, "5f40ff")]
+ internal static void ReadByteString_IndefiniteLength_SupportedConformanceLevel_ShouldSucceed(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ reader.ReadStartByteStringIndefiniteLength();
+ reader.ReadByteString();
+ reader.ReadEndByteStringIndefiniteLength();
+ }
+
+ [Theory]
+ [InlineData(CborConformanceLevel.Lax, "5f40ff")]
+ [InlineData(CborConformanceLevel.Strict, "5f40ff")]
+ internal static void ReadByteString_IndefiniteLength_AsSingleItem_SupportedConformanceLevel_ShouldSucceed(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ reader.ReadByteString();
+ }
+
+ [Theory]
+ [InlineData(CborConformanceLevel.Rfc7049Canonical, "5f40ff")]
+ [InlineData(CborConformanceLevel.Ctap2Canonical, "5f40ff")]
+ internal static void ReadByteString_IndefiniteLength_UnSupportedConformanceLevel_ShouldThrowFormatExceptoin(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ Assert.Throws<FormatException>(() => reader.ReadStartByteStringIndefiniteLength());
+ Assert.Equal(0, reader.BytesRead);
+ }
+
+ [Theory]
+ [InlineData(CborConformanceLevel.Rfc7049Canonical, "5f40ff")]
+ [InlineData(CborConformanceLevel.Ctap2Canonical, "5f40ff")]
+ internal static void ReadByteString_IndefiniteLength_AsSingleItem_UnSupportedConformanceLevel_ShouldThrowFormatException(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ Assert.Throws<FormatException>(() => reader.ReadByteString());
+ Assert.Equal(0, reader.BytesRead);
+ }
+
+ [Theory]
+ [InlineData(CborConformanceLevel.Lax, "7f60ff")]
+ [InlineData(CborConformanceLevel.Strict, "7f60ff")]
+ internal static void ReadTextString_IndefiniteLength_SupportedConformanceLevel_ShouldSucceed(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ reader.ReadStartTextStringIndefiniteLength();
+ reader.ReadTextString();
+ reader.ReadEndTextStringIndefiniteLength();
+ }
+
+ [Theory]
+ [InlineData(CborConformanceLevel.Lax, "7f60ff")]
+ [InlineData(CborConformanceLevel.Strict, "7f60ff")]
+ internal static void ReadTextString_IndefiniteLength_AsSingleItem_SupportedConformanceLevel_ShouldSucceed(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ reader.ReadTextString();
+ }
+
+ [Theory]
+ [InlineData(CborConformanceLevel.Rfc7049Canonical, "7f60ff")]
+ [InlineData(CborConformanceLevel.Ctap2Canonical, "7f60ff")]
+ internal static void ReadTextString_IndefiniteLength_UnSupportedConformanceLevel_ShouldThrowFormatExceptoin(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ Assert.Throws<FormatException>(() => reader.ReadStartTextStringIndefiniteLength());
+ Assert.Equal(0, reader.BytesRead);
+ }
+
+ [Theory]
+ [InlineData(CborConformanceLevel.Rfc7049Canonical, "7f60ff")]
+ [InlineData(CborConformanceLevel.Ctap2Canonical, "7f60ff")]
+ internal static void ReadTextString_IndefiniteLength_AsSingleItem_UnSupportedConformanceLevel_ShouldThrowFormatException(CborConformanceLevel level, string hexEncoding)
+ {
+ byte[] encoding = hexEncoding.HexToByteArray();
+ var reader = new CborReader(encoding, level);
+ Assert.Throws<FormatException>(() => reader.ReadTextString());
+ Assert.Equal(0, reader.BytesRead);
+ }
+
+ [Theory]
[InlineData("00")] // 0
[InlineData("20")] // -1
[InlineData("60")] // empty text string