diff --git a/CBOR.nuspec b/CBOR.nuspec index a12ccf26..de952a69 100644 --- a/CBOR.nuspec +++ b/CBOR.nuspec @@ -1,8 +1,12 @@ 4.5.1PeterO.CborfalseVersion 4.5.1 +>4.5.2PeterO.CborfalseVersion 4.5.2 + +- Bug and regression fixes + +Version 4.5.1 - Fix reported security issue - + Version 4.5: - Add support for JSON Pointers and JSON Patches @@ -12,4 +16,4 @@ Version 4.5: - Add support for deserializing CBOR objects to IReadOnlyList, IReadOnlyCollection, and ReadOnlyDictionary Note that after version 4.5x, the CBOR library's repository will stop including special projects for .NET 2.0 and .NET 4.0, leaving the .NET-Standard project for building the library.CC0-1.0https://github.com/peteroupc/CBORPeter OccilA C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.Peter OccilCBOR (Concise Binary Object Representation)cbor data serialization binary json \ No newline at end of file +> diff --git a/CBOR/CBOR.csproj b/CBOR/CBOR.csproj index fae8d457..553aace8 100644 --- a/CBOR/CBOR.csproj +++ b/CBOR/CBOR.csproj @@ -3,7 +3,7 @@ netstandard1.0 True - 4.5.1 + 4.5.2 Peter Occil A C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949. A C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949. @@ -13,10 +13,14 @@ CC0-1.0 https://github.com/peteroupc/CBOR +Version 4.5.2 + +- Bug and regression fixes + Version 4.5.1 - Fix reported security issue - + Version 4.5: - Add support for JSON Pointers and JSON Patches diff --git a/CBOR/PeterO/Cbor/CBORDataUtilities.cs b/CBOR/PeterO/Cbor/CBORDataUtilities.cs index 6e3f6d47..22c519cb 100644 --- a/CBOR/PeterO/Cbor/CBORDataUtilities.cs +++ b/CBOR/PeterO/Cbor/CBORDataUtilities.cs @@ -121,6 +121,7 @@ internal static string ToStringHelper(CBORObject obj, int depth) { sb.Append(HexAlphabet[(cp >> 8) & 15]); sb.Append(HexAlphabet[(cp >> 4) & 15]); sb.Append(HexAlphabet[cp & 15]); + ++i; } else if (cp >= 0x7F || cp < 0x20 || cp == (int)'\\' || cp == (int)'\"') { sb.Append("\\u"); diff --git a/CBOR/PeterO/Cbor/CBORObject.cs b/CBOR/PeterO/Cbor/CBORObject.cs index af91f170..3e0fb787 100644 --- a/CBOR/PeterO/Cbor/CBORObject.cs +++ b/CBOR/PeterO/Cbor/CBORObject.cs @@ -7942,12 +7942,8 @@ private static int MapCompare( if (listACount != listBCount) { return listACount < listBCount ? -1 : 1; } - var sortedASet = new List(mapA.Keys); - var sortedBSet = new List(mapB.Keys); - // DebugUtility.Log("---sorting mapA's keys"); - // sortedASet.Sort(); - // DebugUtility.Log("---sorting mapB's keys"); - // sortedBSet.Sort(); + var sortedASet = new List(PropertyMap.GetSortedKeys(mapA)); + var sortedBSet = new List(PropertyMap.GetSortedKeys(mapB)); // DebugUtility.Log("---done sorting"); listACount = sortedASet.Count; listBCount = sortedBSet.Count; diff --git a/CBOR/PeterO/Cbor/CBORUtilities.cs b/CBOR/PeterO/Cbor/CBORUtilities.cs index ba540dd9..3fe933a5 100644 --- a/CBOR/PeterO/Cbor/CBORUtilities.cs +++ b/CBOR/PeterO/Cbor/CBORUtilities.cs @@ -469,8 +469,10 @@ public static int ByteArrayCompare(byte[] a, byte[] b) { } int c = Math.Min(a.Length, b.Length); for (var i = 0; i < c; ++i) { - if (a[i] != b[i]) { - return (a[i] < b[i]) ? -1 : 1; + byte ai = a[i]; + byte bi = b[i]; + if (ai != bi) { + return ((((int)ai) & 0xff) < (((int)bi) & 0xff)) ? -1 : 1; } } return (a.Length != b.Length) ? ((a.Length < b.Length) ? -1 : 1) : 0; @@ -487,8 +489,10 @@ public static int ByteArrayCompareLengthFirst(byte[] a, byte[] b) { return a.Length < b.Length ? -1 : 1; } for (var i = 0; i < a.Length; ++i) { - if (a[i] != b[i]) { - return (a[i] < b[i]) ? -1 : 1; + byte ai = a[i]; + byte bi = b[i]; + if (ai != bi) { + return ((((int)ai) & 0xff) < (((int)bi) & 0xff)) ? -1 : 1; } } return 0; diff --git a/CBOR/PeterO/Cbor/PropertyMap.cs b/CBOR/PeterO/Cbor/PropertyMap.cs index ce82517f..4a49a42a 100644 --- a/CBOR/PeterO/Cbor/PropertyMap.cs +++ b/CBOR/PeterO/Cbor/PropertyMap.cs @@ -35,7 +35,7 @@ private sealed class OrderedDictionary : private readonly IDictionary dict; private readonly LinkedList list; public OrderedDictionary() { - this.dict = new Dictionary(); + this.dict = new SortedDictionary(); this.list = new LinkedList(); } public void Add(KeyValuePair kvp) { @@ -179,6 +179,12 @@ public ICollection Keys { } } + public ICollection SortedKeys { + get { + return this.dict.Keys; + } + } + public ICollection Values { get { return new ValueWrapper(this.dict, this.list); @@ -895,6 +901,21 @@ public static object EnumToObjectAsInteger(Enum value) { Convert.ToInt32(value, CultureInfo.InvariantCulture)); } + public static ICollection + GetSortedKeys( + IDictionary dict) { + var odict = dict as OrderedDictionary; + if (odict != null) { + return odict.SortedKeys; + } + var sdict = dict as SortedDictionary; + if (sdict != null) { + return sdict.Keys; + } + throw new InvalidOperationException("Internal error: Map doesn't" + +"\u0020support sorted keys"); + } + public static ICollection> GetEntries( IDictionary dict) { diff --git a/CBOR20/Properties/AssemblyInfo.cs b/CBOR20/Properties/AssemblyInfo.cs index f10c9dfa..297fe8f4 100644 --- a/CBOR20/Properties/AssemblyInfo.cs +++ b/CBOR20/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ using System.Reflection; [assembly: System.CLSCompliant(true)] -[assembly: AssemblyInformationalVersion("4.5.1")] -[assembly: AssemblyVersion("4.5.1.0")] -[assembly: AssemblyFileVersion("4.5.1.0")] +[assembly: AssemblyInformationalVersion("4.5.2")] +[assembly: AssemblyVersion("4.5.2.0")] +[assembly: AssemblyFileVersion("4.5.2.0")] [assembly: AssemblyProduct("CBOR (Concise Binary Object Representati" + "on)")] [assembly: AssemblyTitle("CBOR (Concise Binary Object Representati" + diff --git a/CBOR40/Properties/AssemblyInfo.cs b/CBOR40/Properties/AssemblyInfo.cs index f10c9dfa..297fe8f4 100644 --- a/CBOR40/Properties/AssemblyInfo.cs +++ b/CBOR40/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ using System.Reflection; [assembly: System.CLSCompliant(true)] -[assembly: AssemblyInformationalVersion("4.5.1")] -[assembly: AssemblyVersion("4.5.1.0")] -[assembly: AssemblyFileVersion("4.5.1.0")] +[assembly: AssemblyInformationalVersion("4.5.2")] +[assembly: AssemblyVersion("4.5.2.0")] +[assembly: AssemblyFileVersion("4.5.2.0")] [assembly: AssemblyProduct("CBOR (Concise Binary Object Representati" + "on)")] [assembly: AssemblyTitle("CBOR (Concise Binary Object Representati" + diff --git a/CBORTest/CBORGenerator.cs b/CBORTest/CBORGenerator.cs index b5a00895..b6916eb0 100644 --- a/CBORTest/CBORGenerator.cs +++ b/CBORTest/CBORGenerator.cs @@ -84,7 +84,13 @@ private static void GenerateArgument( private static int[] valueMajorTypes = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, - 4, 5, 6, 6, 7, 7, 7, 7, 7, 7, + 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, + }; + + private static int[] + valueMajorTypesHighDepth = { + 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 6, 7, }; private static int[] valueMajorTypesHighLength = { @@ -130,20 +136,50 @@ private static void GenerateUtf8(IRandomGenExtended ra, ByteWriter bs, int } } + private void GenerateSmall(IRandomGenExtended r, int depth, ByteWriter bs) { + int v = r.GetInt32(100); + if (v < 25) { + GenerateArgument(r, 0, r.GetInt32(100), bs); + } else if (v < 35) { + bs.Write(0x41); + bs.Write(0x20); + } else if (v < 45) { + bs.Write(0x41); + bs.Write(0x20); + } else if (v < 50) { + bs.Write(0x81); + this.GenerateSmall(r, depth + 1, bs); + } else if (v < 53) { + bs.Write(0xa2); + bs.Write(0xf7); + bs.Write(0xf6); + this.GenerateSmall(r, depth + 1, bs); + bs.Write(0xf5); + } else if (v < 80) { + bs.Write(r.GetInt32(0x40)); + } else if (v < 100) { + bs.Write(r.GetInt32(0x60)); + } + } private void Generate(IRandomGenExtended r, int depth, ByteWriter bs) { int majorType = valueMajorTypes[r.GetInt32(valueMajorTypes.Length)]; + if (depth > 6) { + majorType = valueMajorTypesHighDepth[r.GetInt32( + valueMajorTypesHighDepth.Length)]; + } if (bs.ByteLength > 2000000) { majorType = valueMajorTypesHighLength[r.GetInt32( valueMajorTypesHighLength.Length)]; } - if (majorType == 3 || majorType == 2) { + if (majorType == 3 || majorType == 2) { // Byte and text strings int len = r.GetInt32(1000); if (r.GetInt32(50) == 0 && depth < 2) { var v = (long)r.GetInt32(100000) * r.GetInt32(100000); len = (int)(v / 100000); - } - if (depth > 6) { + } else if (depth > 6) { len = r.GetInt32(100) == 0 ? 1 : 0; + } else if (depth > 2) { + len = r.GetInt32(16) + 1; } // TODO: Ensure key uniqueness if (r.GetInt32(2) == 0) { @@ -174,11 +210,18 @@ private void Generate(IRandomGenExtended r, int depth, ByteWriter bs) { } } return; - } else if (majorType == 4 || majorType == 5) { + } else if (majorType == 4 || majorType == 5) { // Arrays and maps int len = r.GetInt32(8); if (r.GetInt32(50) == 0 && depth < 2) { var v = (long)r.GetInt32(1000) * r.GetInt32(1000); len = (int)(v / 1000); + } else if (depth > 6) { + len = r.GetInt32(100) == 0 ? 1 : 0; + } else if (depth > 2) { + len = r.GetInt32(3) + 1; + } + if (depth > 6) { + len = r.GetInt32(100) < 50 ? 1 : (r.GetInt32(100) < 10 ? 2 : 0); } bool indefiniteLength = r.GetInt32(2) == 0; if (indefiniteLength) { @@ -187,7 +230,11 @@ private void Generate(IRandomGenExtended r, int depth, ByteWriter bs) { GenerateArgument(r, majorType, len, bs); } for (int i = 0; i < len; ++i) { - this.Generate(r, depth + 1, bs); + if (depth > 6) { + this.GenerateSmall(r, depth + 1, bs); + } else { + this.Generate(r, depth + 1, bs); + } if (majorType == 5) { this.Generate(r, depth + 1, bs); } @@ -229,7 +276,7 @@ private void Generate(IRandomGenExtended r, int depth, ByteWriter bs) { } break; } - if (majorType == 6) { + if (majorType == 6) { // Tags this.Generate(r, depth + 1, bs); } } diff --git a/CBORTest/CBORObjectTest.cs b/CBORTest/CBORObjectTest.cs index b04e0362..83734a45 100644 --- a/CBORTest/CBORObjectTest.cs +++ b/CBORTest/CBORObjectTest.cs @@ -9721,6 +9721,313 @@ public void TestFromJsonStringLongKindIntOrFloat2() { Assert.IsTrue(cbor.AsDoubleValue() == Double.NegativeInfinity); } +[Test] +public void TestRoundTripRegressions() { +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1;keepkeyorder=1"); +var bytes = new byte[] { + (byte)0xba, 0x00, 0x00, 0x00, 0x03, + (byte)0xf9, + (byte)0x83, 0x1d, + (byte)0xda, + (byte)0xb6, + (byte)0xda, 0x50, 0x56, 0x1a, 0x50, + (byte)0xe3, 0x2c, 0x7a, 0x16, + (byte)0xfa, 0x50, 0x32, 0x73, 0x07, + (byte)0xfa, (byte)0xb9, 0x2d, 0x73, (byte)0xce, 0x38, (byte)0xd0, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1;keepkeyorder=1"); +var bytes = new byte[] { + (byte)0xbf, + (byte)0x9f, + (byte)0xbf, 0x39, 0x20, + (byte)0x8f, 0x4a, 0x1f, 0x46, 0x26, 0x0b, 0x3e, 0x72, 0x2c, 0x7f, 0x11, + 0x2e, 0x39, + (byte)0x9d, + (byte)0xba, 0x1a, 0x11, + (byte)0x8d, + (byte)0xc0, + (byte)0xb4, 0x38, + (byte)0xb6, + (byte)0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + (byte)0xd8, 0x3b, + (byte)0x99, 0x00, 0x02, 0x3b, 0x05, + (byte)0xbb, + (byte)0xea, + (byte)0x8e, 0x4b, + (byte)0xd3, 0x5e, 0x22, + (byte)0x9f, 0x59, 0x00, 0x00, + (byte)0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x41, 0x20, + (byte)0xbf, 0x1a, 0x00, 0x00, 0x00, 0x61, + (byte)0xb9, 0x00, 0x01, 0x1a, 0x00, 0x00, 0x00, 0x0e, + (byte)0xba, 0x00, 0x00, 0x00, 0x00, + (byte)0xff, + (byte)0xff, + (byte)0xff, + (byte)0xd8, 0x22, + (byte)0xf8, + (byte)0x93, + (byte)0xd9, + (byte)0xaf, 0x33, 0x19, + (byte)0xf0, + (byte)0xf0, + (byte)0xf9, + (byte)0x85, + (byte)0x93, + (byte)0x99, 0x00, 0x01, 0x3a, + (byte)0xb5, + (byte)0xfb, 0x4d, 0x43, + (byte)0x98, 0x00, + (byte)0xff, (byte)0xfa, (byte)0xb0, (byte)0xb4, (byte)0xdc, 0x6d, + (byte)0xff, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1;keepkeyorder=1"); +var bytes = new byte[] { + (byte)0xdb, 0x0d, + (byte)0xcb, 0x5d, 0x78, + (byte)0x92, + (byte)0xc2, + (byte)0xc7, 0x2b, + (byte)0xb9, 0x00, 0x02, 0x39, + (byte)0xee, + (byte)0xa0, (byte)0xa0, 0x1a, 0x0e, (byte)0xd9, (byte)0xec, (byte)0xca, + (byte)0xf2, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1;keepkeyorder=1"); +var bytes = new byte[] { + (byte)0xbf, + (byte)0xfb, + (byte)0xb1, 0x21, + (byte)0x93, + (byte)0x8c, + (byte)0xc6, + (byte)0xf3, + (byte)0xcf, + (byte)0xb7, (byte)0xf8, 0x76, 0x18, (byte)0xda, 0x39, 0x60, (byte)0xf4, + (byte)0xff, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1;keepkeyorder=1"); +var bytes = new byte[] { + (byte)0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, (byte)0xf0, 0x0d, 0x2a, 0x21, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1;keepkeyorder=1"); +var bytes = new byte[] { + (byte)0xba, 0x00, 0x00, 0x00, 0x02, + (byte)0xf9, 0x48, 0x37, + (byte)0xda, + (byte)0xb5, 0x72, + (byte)0xcf, + (byte)0xf8, 0x31, 0x3b, 0x06, 0x78, + (byte)0xdb, 0x44, 0x7d, (byte)0xba, (byte)0xbd, 0x7d, 0x39, (byte)0x98, + (byte)0xb9, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1"); +var bytes = new byte[] { + (byte)0xbf, 0x0d, + (byte)0xdb, 0x7f, 0x53, + (byte)0xd5, 0x1e, + (byte)0xab, 0x1f, + (byte)0xb2, + (byte)0xc2, + (byte)0xb8, 0x02, 0x7f, 0x7a, 0x00, 0x00, 0x00, 0x09, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, + (byte)0xbf, 0x00, + (byte)0xf0, + (byte)0x9d, + (byte)0x84, + (byte)0xa1, + (byte)0xff, 0x1a, 0x00, 0x46, 0x31, + (byte)0xdf, 0x7f, 0x69, 0x05, 0x47, 0x76, 0x4f, 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, (byte)0xff, 0x3a, 0x0a, (byte)0xaa, (byte)0xf2, 0x00, + (byte)0xff, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1"); +var bytes = new byte[] { + (byte)0xbf, 0x0d, + (byte)0xdb, 0x7f, 0x53, + (byte)0xd5, 0x1e, + (byte)0xab, 0x1f, 0x23, + (byte)0xc2, + (byte)0xb8, 0x02, 0x7f, 0x69, + (byte)0xc2, + (byte)0xa8, 0x7f, 0x39, 0x7f, + (byte)0xe4, + (byte)0xa1, + (byte)0xae, 0x1c, + (byte)0xff, 0x17, 0x7f, 0x69, 0x05, 0x47, 0x76, 0x4f, 0x01, + (byte)0xec, + (byte)0x90, + (byte)0xb2, 0x0a, (byte)0xff, (byte)0xfa, 0x12, 0x49, 0x20, 0x61, + (byte)0xff, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1"); +var bytes = new byte[] { + (byte)0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, + (byte)0xd8, 0x52, + (byte)0xbf, 0x0c, + (byte)0xf9, 0x68, 0x67, 0x3b, + (byte)0xdb, + (byte)0x85, 0x5b, 0x59, + (byte)0xfd, 0x03, 0x6c, + (byte)0x80, + (byte)0xf8, + (byte)0xc4, 0x7f, 0x67, 0x73, 0x2b, 0x51, 0x31, 0x5d, 0x26, 0x67, + (byte)0xff, 0x5f, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + (byte)0xc7, + (byte)0xb9, 0x6b, + (byte)0xb0, + (byte)0xb6, + (byte)0xbe, 0x6d, + (byte)0x9e, 0x41, 0x34, 0x5a, 0x00, 0x00, 0x00, 0x02, + (byte)0xc4, 0x4a, + (byte)0xff, 0x67, + (byte)0xe1, + (byte)0x99, + (byte)0x92, + (byte)0xf0, + (byte)0xb5, (byte)0xa4, (byte)0xa2, 0x3a, 0x77, 0x11, 0x4c, 0x6f, + (byte)0xff, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1;keepkeyorder=1"); +var bytes = new byte[] { + (byte)0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, + (byte)0x9f, + (byte)0xf9, 0x03, + (byte)0xf1, 0x3b, 0x1a, 0x6f, + (byte)0xc2, 0x1b, + (byte)0xce, 0x23, + (byte)0xcb, 0x2e, + (byte)0xbf, + (byte)0xf8, 0x25, + (byte)0xfb, 0x01, 0x54, 0x4a, 0x78, 0x13, + (byte)0xff, 0x12, + (byte)0x91, + (byte)0xff, + (byte)0xbf, 0x78, 0x04, 0x7a, 0x43, 0x30, 0x04, 0x41, 0x55, 0x7f, 0x7a, + 0x00, 0x00, 0x00, 0x03, + (byte)0xda, + (byte)0xb3, 0x64, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x58, + (byte)0xff, 0x39, (byte)0xa2, 0x48, (byte)0xff, (byte)0xff, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1"); +var bytes = new byte[] { + (byte)0x81, + (byte)0xda, + (byte)0x8a, 0x18, 0x00, 0x00, + (byte)0xda, + (byte)0xd5, + (byte)0xf5, + (byte)0x96, 0x10, + (byte)0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + (byte)0xbf, 0x6f, 0x22, 0x65, 0x65, + (byte)0xf1, + (byte)0x86, + (byte)0x9d, + (byte)0xad, 0x22, 0x42, + (byte)0xc5, + (byte)0xb1, 0x62, 0x58, 0x01, 0x5e, + (byte)0xda, 0x47, 0x47, + (byte)0x87, + (byte)0x94, + (byte)0xed, 0x7f, 0x6c, + (byte)0xf0, + (byte)0x9c, + (byte)0xbc, + (byte)0x96, 0x2f, 0x47, 0x7c, 0x00, 0x50, 0x67, 0x67, 0x10, 0x78, 0x03, + (byte)0xc3, + (byte)0x90, 0x17, + (byte)0xff, 0x19, + (byte)0xd2, + (byte)0xe7, + (byte)0x99, 0x00, 0x01, 0x1b, 0x2a, 0x6e, 0x6f, 0x67, 0x4b, 0x18, 0x60, + 0x51, 0x1b, 0x46, + (byte)0x9f, (byte)0xd3, (byte)0xb7, (byte)0xf4, 0x74, (byte)0xad, 0x6c, + (byte)0xff, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +{ +var options = new CBOREncodeOptions("allowduplicatekeys=1;keepkeyorder=1"); +var bytes = new byte[] { + (byte)0xda, + (byte)0xcf, + (byte)0xf0, + (byte)0xbe, 0x18, + (byte)0x99, 0x00, 0x01, + (byte)0xb9, 0x00, 0x01, + (byte)0xbf, 0x7f, 0x61, 0x5d, 0x7a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, + 0x20, 0x5a, 0x66, 0x1c, 0x7a, 0x00, 0x00, 0x00, 0x02, 0x7d, 0x7f, 0x60, + 0x78, 0x01, 0x43, + (byte)0xff, 0x1a, + (byte)0xca, 0x5c, + (byte)0x83, 0x47, 0x7f, 0x79, 0x00, 0x0a, + (byte)0xcc, + (byte)0x88, 0x00, 0x73, 0x5f, 0x00, 0x26, 0x08, 0x72, 0x60, + (byte)0xff, 0x00, + (byte)0xff, 0x1b, + (byte)0xbb, 0x19, (byte)0xbf, (byte)0x9f, 0x55, (byte)0xee, 0x56, 0x09, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes, options)); +} +} +[Test] +public void TestMapCompareRegressions() { + CBORObject m1, m2; + m1 = CBORObject.NewMap().Add(3, 4).Add(1, 2); + m2 = CBORObject.NewOrderedMap().Add(3, 4).Add(1, 2); + Assert.AreEqual(0, m1.CompareTo(m2)); + TestCommon.CompareTestEqualAndConsistent(m1, m2); + m1 = CBORObject.NewMap().Add(3, 2).Add(1, 2); + m2 = CBORObject.NewOrderedMap().Add(3, 4).Add(1, 2); + TestCommon.CompareTestLess(m1, m2); + m1 = CBORObject.NewMap().Add(3, 7).Add(1, 2); + m2 = CBORObject.NewOrderedMap().Add(3, 4).Add(1, 2); + TestCommon.CompareTestGreater(m1, m2); + m1 = CBORObject.NewMap().Add(3, 4).Add(1, 0); + m2 = CBORObject.NewOrderedMap().Add(3, 4).Add(1, 2); + TestCommon.CompareTestLess(m1, m2); + m1 = CBORObject.NewMap().Add(3, 4).Add(1, 7); + m2 = CBORObject.NewOrderedMap().Add(3, 4).Add(1, 2); + TestCommon.CompareTestGreater(m1, m2); +} [Test] public void TestToObject_TypeMapper() { var mapper = new CBORTypeMapper() @@ -9754,5 +10061,671 @@ public void TestToObject_TypeMapper() { stringTemp); } } + +[Test] +public void TestRegressionFour() { + CBORObject o1 = CBORObject.FromObject(new byte[] { (byte)5, (byte)2 }); + CBORObject o2 = CBORObject.FromObject(new byte[] { (byte)0x85, (byte)2 }); + TestCommon.CompareTestLess(o1, o2); +} + +[Test] +public void TestRegressionOne() { +{ +CBOREncodeOptions options = new CBOREncodeOptions(); +byte[] bytes = new byte[] { + (byte)0xbf, 0x0d, + (byte)0xdb, 0x7f, 0x53, + (byte)0xd5, 0x1e, + (byte)0xab, 0x1f, + (byte)0xb2, + (byte)0xc2, + (byte)0xb8, 0x02, 0x7f, 0x7a, 0x00, 0x00, 0x00, 0x09, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, + (byte)0xbf, 0x00, + (byte)0xf0, + (byte)0x9d, + (byte)0x84, + (byte)0xa1, + (byte)0xff, 0x1a, 0x00, 0x46, 0x31, + (byte)0xdf, 0x7f, 0x69, 0x05, 0x47, 0x76, 0x4f, 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, (byte)0xff, 0x3a, 0x0a, (byte)0xaa, (byte)0xf2, 0x00, + (byte)0xff, +}; +byte[] encodedBytes = new byte[] { + (byte)0xa1, 0x0d, + (byte)0xdb, 0x7f, 0x53, + (byte)0xd5, 0x1e, + (byte)0xab, 0x1f, + (byte)0xb2, + (byte)0xc2, + (byte)0xa2, 0x69, 0x05, 0x47, 0x76, 0x4f, 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, 0x3a, 0x0a, + (byte)0xaa, + (byte)0xf2, 0x00, 0x69, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, + (byte)0xbf, 0x00, + (byte)0xf0, (byte)0x9d, (byte)0x84, (byte)0xa1, 0x1a, 0x00, 0x46, 0x31, + (byte)0xdf, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes)); +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(encodedBytes)); +} +} + +[Test] +public void TestRegressionTwo() { +{ +CBOREncodeOptions options = new CBOREncodeOptions(); +byte[] bytes = new byte[] { + (byte)0xb8, 0x02, 0x7f, 0x7a, 0x00, 0x00, 0x00, + 0x09, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, + (byte)0xbf, 0x00, + (byte)0xf0, + (byte)0x9d, + (byte)0x84, + (byte)0xa1, + (byte)0xff, 0x1a, 0x00, 0x46, 0x31, + (byte)0xdf, 0x7f, 0x69, 0x05, 0x47, 0x76, 0x4f, 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, (byte)0xff, 0x3a, 0x0a, (byte)0xaa, (byte)0xf2, 0x00, +}; +byte[] encodedBytes = new byte[] { + (byte)0xa2, 0x69, 0x05, 0x47, 0x76, 0x4f, + 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, 0x3a, 0x0a, + (byte)0xaa, + (byte)0xf2, 0x00, 0x69, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, + (byte)0xbf, 0x00, + (byte)0xf0, (byte)0x9d, (byte)0x84, (byte)0xa1, 0x1a, 0x00, 0x46, 0x31, + (byte)0xdf, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes)); +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(encodedBytes)); +} +} + +[Test] +public void TestRegressionThree() { +{ +CBOREncodeOptions options = new CBOREncodeOptions(); +byte[] bytes = new byte[] { + (byte)0xb8, 0x02, 0x7f, 0x7a, 0x00, 0x00, 0x00, + 0x09, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, + (byte)0xbf, 0x00, + (byte)0xf0, + (byte)0x9d, + (byte)0x84, + (byte)0xa1, + (byte)0xff, 0, 0x7f, 0x69, 0x05, 0x47, 0x76, 0x4f, 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, (byte)0xff, 0, +}; +byte[] encodedBytes = new byte[] { + (byte)0xa2, 0x69, 0x05, 0x47, 0x76, 0x4f, + 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, 0, 0x69, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, (byte)0xbf, 0x00, (byte)0xf0, (byte)0x9d, (byte)0x84, + (byte)0xa1, 0, +}; +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(bytes)); +CBORTestCommon.AssertRoundTrip(CBORObject.DecodeFromBytes(encodedBytes)); +} +} + +[Test] +public void TestStringCompareBug() { + CBORObject a, b, c, d; + var bytes = new byte[] { + 0x69, 0x05, 0x47, 0x76, 0x4f, 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, + }; + a = CBORObject.DecodeFromBytes(bytes); + c = a; + bytes = new byte[] { + 0x7f, 0x69, 0x05, 0x47, 0x76, 0x4f, 0x01, + (byte)0xf4, + (byte)0x80, + (byte)0x80, + (byte)0x80, (byte)0xff, + }; + b = CBORObject.DecodeFromBytes(bytes); + d = b; + TestCommon.CompareTestEqual(a, b); + bytes = new byte[] { + 0x7f, 0x7a, 0x00, 0x00, 0x00, 0x09, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, + (byte)0xbf, 0x00, + (byte)0xf0, + (byte)0x9d, + (byte)0x84, + (byte)0xa1, + (byte)0xff, + }; + a = CBORObject.DecodeFromBytes(bytes); + bytes = new byte[] { + 0x7f, 0x69, + (byte)0xf0, + (byte)0xb8, + (byte)0xbf, + (byte)0xbf, 0x00, + (byte)0xf0, + (byte)0x9d, + (byte)0x84, + (byte)0xa1, + (byte)0xff, + }; + b = CBORObject.DecodeFromBytes(bytes); + TestCommon.CompareTestEqual(a, b); + TestCommon.CompareTestLess(c, a); + TestCommon.CompareTestLess(c, b); + TestCommon.CompareTestLess(d, a); + TestCommon.CompareTestLess(d, b); + CBORObject o1 = CBORObject.NewMap(); + o1.Add(b, CBORObject.FromObject(0)); + o1.Add(c, CBORObject.FromObject(0)); + CBORObject o2 = CBORObject.NewMap(); + o2.Add(c, CBORObject.FromObject(0)); + o2.Add(b, CBORObject.FromObject(0)); + TestCommon.CompareTestEqual(a, b); +} + +[Test] +[Timeout(2000)] +public void TestSlowDecode() { +byte[] bytes = new byte[] { + (byte)0xa4, + (byte)0xa3, + (byte)0xa4, + (byte)0xa3, + (byte)0xa3, + (byte)0xf0, 0x02, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, 0x02, + (byte)0xf7, + (byte)0xa0, 0x02, + (byte)0xa3, + (byte)0xf0, 0x01, + (byte)0xf1, 0x01, + (byte)0xf2, + (byte)0xf7, + (byte)0xf7, + (byte)0xf5, + (byte)0xa0, 0x01, + (byte)0xa3, + (byte)0xa3, 0x00, + (byte)0xf5, 0x01, + (byte)0xf4, 0x02, 0x02, 0x02, + (byte)0xa0, 0x01, + (byte)0xa3, 0x00, + (byte)0xa0, 0x01, + (byte)0xa0, 0x02, 0x02, + (byte)0xf6, 0x02, 0x40, + (byte)0xf5, 0x02, + (byte)0xa4, + (byte)0xa3, + (byte)0xf0, 0x02, + (byte)0xf1, + (byte)0xf7, + (byte)0xf2, + (byte)0xf6, 0x00, + (byte)0xa3, + (byte)0xa4, + (byte)0xa3, + (byte)0xf1, + (byte)0xf4, + (byte)0xf2, 0x02, + (byte)0xf3, 0x01, 0x02, + (byte)0xa0, + (byte)0xa0, + (byte)0xa3, + (byte)0xf0, 0x00, + (byte)0xf1, + (byte)0xf7, + (byte)0xf2, + (byte)0xf5, 0x00, 0x40, + (byte)0xf4, + (byte)0xf4, + (byte)0xa4, 0x00, + (byte)0xf6, 0x01, + (byte)0xf4, 0x02, 0x00, 0x40, 0x01, + (byte)0xf5, + (byte)0xa4, + (byte)0xf0, + (byte)0xa0, + (byte)0xf1, + (byte)0xa0, + (byte)0xf2, + (byte)0xf4, 0x40, 0x00, 0x02, 0x01, + (byte)0xa3, + (byte)0xa3, + (byte)0xf1, + (byte)0xf6, + (byte)0xf2, + (byte)0xf6, + (byte)0xf3, + (byte)0xf4, + (byte)0xa0, + (byte)0xa3, 0x00, 0x00, 0x01, + (byte)0xf4, 0x02, + (byte)0xf7, + (byte)0xf6, + (byte)0xa3, + (byte)0xa4, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, + (byte)0xf6, + (byte)0xf3, 0x01, 0x40, + (byte)0xa0, 0x00, + (byte)0xa4, 0x00, 0x02, 0x01, + (byte)0xa0, 0x02, 0x01, 0x40, 0x00, + (byte)0xf4, + (byte)0xa4, + (byte)0xa4, + (byte)0xa3, + (byte)0xf0, + (byte)0xf5, + (byte)0xf1, + (byte)0xf7, + (byte)0xf2, + (byte)0xf7, + (byte)0xf4, + (byte)0xa3, 0x00, + (byte)0xf6, 0x01, 0x02, 0x02, + (byte)0xf5, + (byte)0xf5, + (byte)0xa3, + (byte)0xa3, + (byte)0xa3, + (byte)0xf0, + (byte)0xf4, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, + (byte)0xf6, 0x01, + (byte)0xa3, + (byte)0xa4, + (byte)0xa4, + (byte)0xa3, + (byte)0xa4, + (byte)0xa3, + (byte)0xa3, + (byte)0xf0, + (byte)0xf4, + (byte)0xf1, + (byte)0xf6, + (byte)0xf2, 0x02, 0x01, + (byte)0xa0, + (byte)0xf6, + (byte)0xa3, + (byte)0xf1, + (byte)0xf7, + (byte)0xf2, 0x00, + (byte)0xf3, 0x01, 0x01, + (byte)0xf4, + (byte)0xa3, + (byte)0xf1, 0x01, + (byte)0xf2, 0x00, + (byte)0xf3, + (byte)0xf6, + (byte)0xf5, + (byte)0xa3, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, + (byte)0xa0, + (byte)0xf3, + (byte)0xf6, + (byte)0xf4, 0x40, 0x02, 0x02, + (byte)0xa4, + (byte)0xa3, + (byte)0xa4, + (byte)0xf1, + (byte)0xf7, + (byte)0xf2, + (byte)0xf4, + (byte)0xf3, + (byte)0xf7, 0x40, 0x01, 0x00, + (byte)0xa4, + (byte)0xf0, + (byte)0xf6, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, 0x00, 0x40, + (byte)0xf5, + (byte)0xa0, + (byte)0xa4, + (byte)0xa3, 0x00, 0x00, 0x01, + (byte)0xf5, 0x02, + (byte)0xf6, 0x00, + (byte)0xa0, 0x00, + (byte)0xa3, 0x00, 0x02, 0x01, 0x02, 0x02, 0x00, 0x02, 0x40, 0x02, 0x00, + (byte)0xf6, + (byte)0xa3, 0x00, + (byte)0xf7, 0x01, 0x00, 0x02, 0x01, 0x02, + (byte)0xa3, + (byte)0xa4, + (byte)0xa4, 0x00, + (byte)0xf4, 0x01, + (byte)0xf5, 0x02, 0x00, 0x40, + (byte)0xf7, 0x00, + (byte)0xa4, + (byte)0xf1, + (byte)0xf6, + (byte)0xf2, + (byte)0xf4, + (byte)0xf3, + (byte)0xf5, 0x40, + (byte)0xa0, + (byte)0xf7, + (byte)0xa4, 0x00, 0x00, 0x01, + (byte)0xa0, 0x02, + (byte)0xf5, 0x40, 0x00, 0x02, 0x40, 0x01, + (byte)0xf7, + (byte)0xa4, + (byte)0xa3, + (byte)0xa3, 0x00, + (byte)0xf6, 0x01, + (byte)0xf4, 0x02, + (byte)0xf4, 0x02, + (byte)0xa3, + (byte)0xf0, + (byte)0xf6, + (byte)0xf1, + (byte)0xf4, + (byte)0xf2, 0x01, + (byte)0xf4, + (byte)0xa3, + (byte)0xa4, + (byte)0xa3, + (byte)0xf1, + (byte)0xf4, + (byte)0xf2, + (byte)0xa0, + (byte)0xf3, 0x01, + (byte)0xf6, + (byte)0xa0, + (byte)0xf6, + (byte)0xa3, + (byte)0xf0, + (byte)0xf5, + (byte)0xf1, 0x00, + (byte)0xf2, + (byte)0xf5, 0x02, 0x40, + (byte)0xf6, + (byte)0xf6, + (byte)0xa4, + (byte)0xf0, 0x01, + (byte)0xf1, + (byte)0xf4, + (byte)0xf2, + (byte)0xf6, 0x40, + (byte)0xf4, + (byte)0xa0, + (byte)0xa4, + (byte)0xa3, + (byte)0xa4, 0x00, + (byte)0xa0, 0x01, 0x00, 0x02, + (byte)0xf6, 0x40, + (byte)0xf4, 0x00, + (byte)0xa4, + (byte)0xa4, + (byte)0xf0, + (byte)0xf4, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, 0x00, 0x40, + (byte)0xa0, + (byte)0xf6, + (byte)0xa4, 0x00, 0x00, 0x01, 0x02, 0x02, 0x02, 0x40, + (byte)0xf6, + (byte)0xa0, + (byte)0xa4, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, + (byte)0xf4, + (byte)0xf3, + (byte)0xf4, 0x40, + (byte)0xf5, + (byte)0xa0, 0x40, + (byte)0xf7, 0x02, + (byte)0xa4, + (byte)0xa4, 0x00, 0x02, 0x01, 0x02, 0x02, 0x01, 0x40, + (byte)0xf5, + (byte)0xf7, + (byte)0xa4, + (byte)0xf1, + (byte)0xa0, + (byte)0xf2, + (byte)0xf6, + (byte)0xf3, + (byte)0xf4, 0x40, + (byte)0xf6, + (byte)0xf4, + (byte)0xa4, + (byte)0xf0, 0x00, + (byte)0xf1, + (byte)0xf7, + (byte)0xf2, 0x02, 0x40, + (byte)0xf4, + (byte)0xf4, 0x40, 0x02, + (byte)0xf4, + (byte)0xf6, + (byte)0xa3, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, + (byte)0xf6, + (byte)0xf3, 0x00, + (byte)0xf7, + (byte)0xa3, + (byte)0xf0, + (byte)0xf7, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, 0x00, 0x01, 0x40, 0x01, 0x01, 0x00, + (byte)0xf7, + (byte)0xa0, 0x00, + (byte)0xa3, + (byte)0xa4, + (byte)0xf1, 0x02, + (byte)0xf2, + (byte)0xf4, + (byte)0xf3, + (byte)0xf7, 0x40, + (byte)0xf6, + (byte)0xf7, + (byte)0xa4, + (byte)0xf1, + (byte)0xf6, + (byte)0xf2, + (byte)0xf4, + (byte)0xf3, + (byte)0xf4, 0x40, + (byte)0xf6, + (byte)0xf6, + (byte)0xa4, + (byte)0xa3, + (byte)0xf1, + (byte)0xf6, + (byte)0xf2, 0x00, + (byte)0xf3, + (byte)0xf4, + (byte)0xf5, + (byte)0xa0, + (byte)0xf6, + (byte)0xa3, 0x00, 0x01, 0x01, + (byte)0xa0, 0x02, 0x01, + (byte)0xa0, 0x40, 0x02, 0x00, + (byte)0xf5, 0x40, + (byte)0xf5, + (byte)0xa0, + (byte)0xa4, + (byte)0xa3, 0x00, + (byte)0xf5, 0x01, 0x02, 0x02, 0x00, + (byte)0xf6, + (byte)0xa0, + (byte)0xf6, + (byte)0xa3, + (byte)0xf1, + (byte)0xf6, + (byte)0xf2, + (byte)0xf5, + (byte)0xf3, + (byte)0xf5, 0x00, 0x40, + (byte)0xf5, + (byte)0xf6, 0x02, 0x40, 0x01, 0x01, + (byte)0xa4, + (byte)0xf1, + (byte)0xa0, + (byte)0xf2, 0x01, + (byte)0xf3, + (byte)0xf5, 0x40, 0x00, 0x02, + (byte)0xa0, + (byte)0xa0, 0x00, + (byte)0xa3, + (byte)0xf0, + (byte)0xf4, + (byte)0xf1, + (byte)0xa0, + (byte)0xf2, 0x00, 0x01, 0x40, 0x02, 0x00, + (byte)0xa4, + (byte)0xf0, 0x01, + (byte)0xf1, 0x02, + (byte)0xf2, + (byte)0xa0, 0x40, + (byte)0xf5, 0x02, + (byte)0xa4, + (byte)0xa3, + (byte)0xf0, 0x00, + (byte)0xf1, 0x01, + (byte)0xf2, + (byte)0xf5, + (byte)0xf7, + (byte)0xa3, + (byte)0xa3, + (byte)0xf1, 0x01, + (byte)0xf2, 0x01, + (byte)0xf3, 0x01, + (byte)0xa0, + (byte)0xa0, 0x01, + (byte)0xa3, + (byte)0xf1, + (byte)0xf4, + (byte)0xf2, 0x00, + (byte)0xf3, + (byte)0xf4, + (byte)0xf6, 0x02, + (byte)0xa3, + (byte)0xf1, + (byte)0xf4, + (byte)0xf2, 0x01, + (byte)0xf3, + (byte)0xf4, 0x02, 0x40, 0x00, + (byte)0xa0, 0x40, + (byte)0xa0, + (byte)0xf5, + (byte)0xa4, + (byte)0xf0, + (byte)0xf7, + (byte)0xf1, + (byte)0xf4, + (byte)0xf2, + (byte)0xa0, 0x40, + (byte)0xa0, 0x00, + (byte)0xa4, 0x00, 0x00, 0x01, + (byte)0xa0, 0x02, + (byte)0xf5, 0x40, + (byte)0xf7, + (byte)0xf7, 0x00, + (byte)0xa3, 0x00, 0x01, 0x01, 0x01, 0x02, + (byte)0xf4, + (byte)0xf7, + (byte)0xf7, + (byte)0xa0, + (byte)0xa0, + (byte)0xa3, + (byte)0xf0, + (byte)0xf6, + (byte)0xf1, 0x01, + (byte)0xf2, 0x01, 0x00, + (byte)0xf6, 0x40, + (byte)0xf6, + (byte)0xf6, + (byte)0xa4, + (byte)0xf1, + (byte)0xf7, + (byte)0xf2, 0x01, + (byte)0xf3, 0x01, 0x40, + (byte)0xf7, + (byte)0xf5, + (byte)0xa4, + (byte)0xf1, + (byte)0xf6, + (byte)0xf2, 0x00, + (byte)0xf3, + (byte)0xa0, 0x40, 0x01, 0x02, 0x40, 0x01, + (byte)0xa0, + (byte)0xa0, 0x02, 0x40, 0x01, 0x02, + (byte)0xa4, + (byte)0xf0, + (byte)0xf4, + (byte)0xf1, + (byte)0xf5, + (byte)0xf2, + (byte)0xf5, 0x40, + (byte)0xf7, + (byte)0xa0, + (byte)0xf5, + (byte)0xa0, + (byte)0xf5, + (byte)0xa3, 0x00, ( + byte)0xf6, 0x01, (byte)0xf6, 0x02, (byte)0xa0, (byte)0xf4, 0x40, + (byte)0xf7, +}; +var options = new CBOREncodeOptions("allowduplicatekeys=1"); +for (var i = 0; i < 10; ++i) { + CBORObject.DecodeFromBytes(bytes, options); +} +} } } diff --git a/CBORTest/CBORTestCommon.cs b/CBORTest/CBORTestCommon.cs index 911ce55e..20e1f18f 100644 --- a/CBORTest/CBORTestCommon.cs +++ b/CBORTest/CBORTestCommon.cs @@ -119,7 +119,8 @@ public static CBORObject RandomNumberOrRational(IRandomGenExtended rand) { public static CBORObject RandomCBORMap(IRandomGenExtended rand, int depth) { int x = rand.GetInt32(100); int count = (x < 80) ? 2 : ((x < 93) ? 1 : ((x < 98) ? 0 : 10)); - CBORObject cborRet = CBORObject.NewMap(); + CBORObject cborRet = rand.GetInt32(100) < 30 ? + CBORObject.NewOrderedMap() : CBORObject.NewMap(); for (var i = 0; i < count; ++i) { CBORObject key = RandomCBORObject(rand, depth + 1); CBORObject value = RandomCBORObject(rand, depth + 1); diff --git a/CBORTest/TestCommon.cs b/CBORTest/TestCommon.cs index 287b4af4..b5e558e6 100644 --- a/CBORTest/TestCommon.cs +++ b/CBORTest/TestCommon.cs @@ -761,7 +761,7 @@ private static bool ByteArraysEqual( return true; } - private static bool ByteArraysEqual(byte[] arr1, byte[] arr2) { + public static bool ByteArraysEqual(byte[] arr1, byte[] arr2) { if (arr1 == null) { return arr2 == null; }