public void TestEmptyString() { IIonHashReader ihr = IonHashReaderBuilder .Standard() .WithHasherProvider(new IdentityIonHasherProvider()) .WithReader(IonReaderBuilder.Build("")) .Build(); Assert.AreEqual(IonType.None, ihr.MoveNext()); TestUtil.AssertEquals(new byte[] { }, ihr.Digest(), "Digests don't match."); Assert.AreEqual(IonType.None, ihr.MoveNext()); TestUtil.AssertEquals(new byte[] { }, ihr.Digest(), "Digests don't match."); }
internal static QldbHash ToQldbHash(IIonReader reader) { IIonHashReader hashReader = IonHashReaderBuilder.Standard() .WithHasherProvider(HasherProvider) .WithReader(reader) .Build(); while (hashReader.MoveNext() != IonType.None) { } return(new QldbHash(hashReader.Digest())); }
public void TestTopLevelValues() { IIonHashReader ihr = IonHashReaderBuilder .Standard() .WithHasherProvider(new IdentityIonHasherProvider()) .WithReader(IonReaderBuilder.Build("1 2 3")) .Build(); Assert.AreEqual(IonType.Int, ihr.MoveNext()); TestUtil.AssertEquals(new byte[] { }, ihr.Digest(), "Digests don't match."); Assert.AreEqual(IonType.Int, ihr.MoveNext()); TestUtil.AssertEquals(new byte[] { 0x0b, 0x20, 0x01, 0x0e }, ihr.Digest(), "Digests don't match."); Assert.AreEqual(IonType.Int, ihr.MoveNext()); TestUtil.AssertEquals(new byte[] { 0x0b, 0x20, 0x02, 0x0e }, ihr.Digest(), "Digests don't match."); Assert.AreEqual(IonType.None, ihr.MoveNext()); TestUtil.AssertEquals(new byte[] { 0x0b, 0x20, 0x03, 0x0e }, ihr.Digest(), "Digests don't match."); Assert.AreEqual(IonType.None, ihr.MoveNext()); TestUtil.AssertEquals(new byte[] { }, ihr.Digest(), "Digests don't match."); }
private void Consume(Action <IIonHashReader> lambda) { IIonHashReader ihr = IonHashReaderBuilder .Standard() .WithHasherProvider(new IdentityIonHasherProvider()) .WithReader(IonReaderBuilder.Build("[1,2,{a:3,b:4},5]")) .Build(); TestUtil.AssertEquals(new byte[] { }, ihr.Digest(), "Digests don't match."); lambda(ihr); TestUtil.AssertEquals(new byte[] { 0x0b, 0xb0, 0x0b, 0x20, 0x01, 0x0e, 0x0b, 0x20, 0x02, 0x0e, 0x0b, 0xd0, 0x0c, 0x0b, 0x70, 0x61, 0x0c, 0x0e, 0x0c, 0x0b, 0x20, 0x03, 0x0c, 0x0e, 0x0c, 0x0b, 0x70, 0x62, 0x0c, 0x0e, 0x0c, 0x0b, 0x20, 0x04, 0x0c, 0x0e, 0x0e, 0x0b, 0x20, 0x05, 0x0e, 0x0e }, ihr.Digest(), "Digests don't match."); Assert.AreEqual(IonType.None, ihr.MoveNext()); TestUtil.AssertEquals(new byte[] { }, ihr.Digest(), "Digests don't match."); }
public void Test(TestValue tv, string s) { IIonHashWriter hashWriter = null; try { hashWriter = IonHashWriterBuilder.Standard() .WithWriter(IonTextWriterBuilder.Build(new StringWriter())) .WithHasherProvider(HasherProvider) .Build(); hashWriter.WriteValues(IonReaderBuilder.Build(s)); } catch (IonException e) { if (tv.IsValidIon()) { throw e; } } IIonHashReader hashReader = null; try { hashReader = IonHashReaderBuilder.Standard() .WithReader(IonReaderBuilder.Build(s)) .WithHasherProvider(HasherProvider) .Build(); hashReader.MoveNext(); hashReader.MoveNext(); } catch (IonException e) { if (tv.IsValidIon()) { throw e; } } if (tv.validIon == null || tv.validIon.Value == true) { TestUtil.AssertEquals( hashWriter.Digest(), hashReader.Digest(), "Reader/writer hashes for line |" + tv.AsIon() + "| as |" + s + "| don't match"); } }
private void AssertNoFieldnameInCurrentHash(string value, byte[] expectedBytes) { var reader = IonReaderBuilder.Build(value); reader.MoveNext(); MemoryStream memoryStream = new MemoryStream(); var writer = IonBinaryWriterBuilder.Build(memoryStream); writer.StepIn(IonType.Struct); IIonHashWriter ihw = IonHashWriterBuilder .Standard() .WithHasherProvider(new IdentityIonHasherProvider()) .WithWriter(writer) .Build(); ihw.SetFieldName("field_name"); ihw.WriteValue(reader); byte[] actual = ihw.Digest(); TestUtil.AssertEquals(expectedBytes, actual, "Digest arrays mismatch"); writer.StepOut(); ihw.Finish(); writer.Finish(); memoryStream.Flush(); byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); reader = IonReaderBuilder.Build(bytes); reader.MoveNext(); reader.StepIn(); IIonHashReader ihr = IonHashReaderBuilder .Standard() .WithHasherProvider(new IdentityIonHasherProvider()) .WithReader(reader) .Build(); ihr.MoveNext(); //List ihr.MoveNext(); //none actual = ihr.Digest(); TestUtil.AssertEquals(expectedBytes, actual, "Digest arrays mismatch"); }
public void FieldNameAsymmetry() { var memoryStream = new MemoryStream(); var writer = IonBinaryWriterBuilder.Build(memoryStream); IIonHashWriter ihw = IonHashWriterBuilder .Standard() .WithHasherProvider(new IdentityIonHasherProvider()) .WithWriter(writer) .Build(); // A nested struct: {a:{b:1}} writer.StepIn(IonType.Struct); writer.SetFieldName("a"); ihw.StepIn(IonType.Struct); ihw.SetFieldName("b"); ihw.WriteInt(1); ihw.StepOut(); byte[] writeHash = ihw.Digest(); ihw.Flush(); writer.StepOut(); writer.Flush(); var loader = IonLoader.Default; var ionValue = loader.Load(memoryStream.ToArray()) //Datagram .GetElementAt(0) //first struct .GetField("a"); //inner struct IIonReader reader = IonReaderBuilder.Build(ionValue); IIonHashReader ihr = IonHashReaderBuilder .Standard() .WithReader(reader) .WithHasherProvider(new IdentityIonHasherProvider()) .Build(); ihr.MoveNext(); // struct ihr.MoveNext(); // none TestUtil.AssertEquals(writeHash, ihr.Digest(), "Digest arrays mismatch"); }