public static CBORObject RandomCBORTaggedObject( RandomGenerator rand, int depth) { var tag = 0; if (rand.UniformInt(2) == 0) { int[] tagselection = { 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 30, 30, 30, 0, 1, 25, 26, 27 }; tag = tagselection[rand.UniformInt(tagselection.Length)]; } else { tag = rand.UniformInt(0x1000000); } if (tag == 25) { tag = 0; } if (tag == 30) { return(CBORObject.FromObject(RandomObjects.RandomByteString(rand))); } for (var i = 0; i < 15; ++i) { CBORObject o; // Console.WriteLine("tag "+tag+" "+i); if (tag == 0 || tag == 1 || tag == 28 || tag == 29) { tag = 999; } if (tag == 2 || tag == 3) { o = CBORObject.FromObject(RandomObjects.RandomByteStringShort(rand)); } else if (tag == 4 || tag == 5) { o = CBORObject.NewArray(); o.Add(CBORObject.FromObject(RandomObjects.RandomSmallIntegral(rand))); o.Add(CBORObject.FromObject(RandomObjects.RandomEInteger(rand))); } else if (tag == 30) { o = CBORObject.NewArray(); o.Add(CBORObject.FromObject(RandomObjects.RandomSmallIntegral(rand))); o.Add(CBORObject.FromObject(RandomObjects.RandomEInteger(rand))); } else { o = RandomCBORObject(rand, depth + 1); } try { o = CBORObject.FromObjectAndTag(o, tag); // Console.WriteLine("done"); return(o); } catch (Exception) { continue; } } // Console.WriteLine("Failed "+tag); return(CBORObject.Null); }
public static CBORObject RandomCBORTaggedObject( IRandomGenExtended rand, int depth) { var tag = 0; if (rand.GetInt32(2) == 0) { int[] tagselection = { 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 30, 30, 30, 0, 1, 25, 26, 27, }; tag = tagselection[rand.GetInt32(tagselection.Length)]; } else if (rand.GetInt32(100) < 90) { return(CBORObject.FromObjectAndTag( RandomCBORObject(rand, depth + 1), rand.GetInt32(0x100000))); } else { return(CBORObject.FromObjectAndTag( RandomCBORObject(rand, depth + 1), RandomEIntegerMajorType0(rand))); } if (tag == 25) { tag = 0; } if (tag == 30) { object o = RandomObjects.RandomByteString(rand); return(CBORObject.FromObject(o)); } { CBORObject cbor; // Console.WriteLine("tag "+tag+" "+i); if (tag == 0 || tag == 1 || tag == 28 || tag == 29) { tag = 999; } if (tag == 2 || tag == 3) { object o = RandomObjects.RandomByteStringShort(rand); cbor = CBORObject.FromObject(o); } else if (tag == 4 || tag == 5) { cbor = CBORObject.NewArray(); object o = RandomObjects.RandomSmallIntegral(rand); cbor.Add(o); o = RandomObjects.RandomEInteger(rand); cbor.Add(o); } else if (tag == 30) { cbor = CBORObject.NewArray(); object o = RandomObjects.RandomSmallIntegral(rand); cbor.Add(o); o = RandomObjects.RandomEInteger(rand); cbor.Add(o); } else { cbor = RandomCBORObject(rand, depth + 1); } return(CBORObject.FromObjectAndTag(cbor, tag)); } }
public static CBORObject RandomCBORTaggedObject( RandomGenerator rand, int depth) { var tag = 0; if (rand.UniformInt(2) == 0) { int[] tagselection = { 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 30, 30, 30, 0, 1, 25, 26, 27, }; tag = tagselection[rand.UniformInt(tagselection.Length)]; } else { tag = rand.UniformInt(0x1000000); } if (tag == 25) { tag = 0; } if (tag == 30) { object o = RandomObjects.RandomByteString(rand); return(ToObjectTest.TestToFromObjectRoundTrip(o)); } { CBORObject cbor; // Console.WriteLine("tag "+tag+" "+i); if (tag == 0 || tag == 1 || tag == 28 || tag == 29) { tag = 999; } if (tag == 2 || tag == 3) { object o = RandomObjects.RandomByteStringShort(rand); cbor = ToObjectTest.TestToFromObjectRoundTrip(o); } else if (tag == 4 || tag == 5) { cbor = CBORObject.NewArray(); object o = RandomObjects.RandomSmallIntegral(rand); cbor.Add(ToObjectTest.TestToFromObjectRoundTrip(o)); o = RandomObjects.RandomEInteger(rand); cbor.Add(ToObjectTest.TestToFromObjectRoundTrip(o)); } else if (tag == 30) { cbor = CBORObject.NewArray(); object o = RandomObjects.RandomSmallIntegral(rand); cbor.Add(ToObjectTest.TestToFromObjectRoundTrip(o)); o = RandomObjects.RandomEInteger(rand); cbor.Add(ToObjectTest.TestToFromObjectRoundTrip(o)); } else { cbor = RandomCBORObject(rand, depth + 1); } try { cbor = CBORObject.FromObjectAndTag(cbor, tag); // Console.WriteLine("done"); return(cbor); } catch (Exception) { return(CBORObject.FromObjectAndTag(cbor, 999)); } } }