Exemple #1
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Algorithm  = reader.ReadDomainName();
     Inception  = reader.ReadDateTime32();
     Expiration = reader.ReadDateTime32();
     Mode       = (KeyExchangeMode)reader.ReadUInt16();
     Error      = (MessageStatus)reader.ReadUInt16();
     Key        = reader.ReadUInt16LengthPrefixedBytes();
     OtherData  = reader.ReadUInt16LengthPrefixedBytes();
 }
Exemple #2
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            TypeCovered         = (DnsType)reader.ReadUInt16();
            Algorithm           = (SecurityAlgorithm)reader.ReadByte();
            Labels              = reader.ReadByte();
            OriginalTTL         = reader.ReadTimeSpan32();
            SignatureExpiration = reader.ReadDateTime32();
            SignatureInception  = reader.ReadDateTime32();
            KeyTag              = reader.ReadUInt16();
            SignerName          = reader.ReadDomainName();
            Signature           = reader.ReadBytes(end - reader.Position);
        }
        public void Roundtrip()
        {
            var someBytes = new byte[] { 1, 2, 3 };
            var someDate  = new DateTime(1997, 1, 21, 3, 4, 5, DateTimeKind.Utc);

            var ms     = new MemoryStream();
            var writer = new WireWriter(ms);

            writer.WriteDomainName("emanon.org");
            writer.WriteString("alpha");
            writer.WriteTimeSpan32(TimeSpan.FromHours(3));
            writer.WriteUInt16(ushort.MaxValue);
            writer.WriteUInt32(uint.MaxValue);
            writer.WriteUInt48(0XFFFFFFFFFFFFul);
            writer.WriteBytes(someBytes);
            writer.WriteByteLengthPrefixedBytes(someBytes);
            writer.WriteByteLengthPrefixedBytes(null);
            writer.WriteIPAddress(IPAddress.Parse("127.0.0.1"));
            writer.WriteIPAddress(IPAddress.Parse("2406:e001:13c7:1:7173:ef8:852f:25cb"));
            writer.WriteDateTime32(someDate);
            writer.WriteDateTime48(someDate);

            ms.Position = 0;
            var reader = new WireReader(ms);

            Assert.AreEqual("emanon.org", reader.ReadDomainName());
            Assert.AreEqual("alpha", reader.ReadString());
            Assert.AreEqual(TimeSpan.FromHours(3), reader.ReadTimeSpan32());
            Assert.AreEqual(ushort.MaxValue, reader.ReadUInt16());
            Assert.AreEqual(uint.MaxValue, reader.ReadUInt32());
            Assert.AreEqual(0XFFFFFFFFFFFFul, reader.ReadUInt48());
            CollectionAssert.AreEqual(someBytes, reader.ReadBytes(3));
            CollectionAssert.AreEqual(someBytes, reader.ReadByteLengthPrefixedBytes());
            CollectionAssert.AreEqual(new byte[0], reader.ReadByteLengthPrefixedBytes());
            Assert.AreEqual(IPAddress.Parse("127.0.0.1"), reader.ReadIPAddress());
            Assert.AreEqual(IPAddress.Parse("2406:e001:13c7:1:7173:ef8:852f:25cb"), reader.ReadIPAddress(16));
            Assert.AreEqual(someDate, reader.ReadDateTime32());
            Assert.AreEqual(someDate, reader.ReadDateTime48());
        }