Example #1
0
        /// <inheritdoc />
        public override IWireSerialiser Read(WireReader reader)
        {
            // Read standard properties of a resource record.
            Name  = reader.ReadDomainName();
            Type  = (DnsType)reader.ReadUInt16();
            Class = (DnsClass)reader.ReadUInt16();
            TTL   = reader.ReadTimeSpan32();
            int length = reader.ReadUInt16();

            // Find a specific class for the TYPE or default
            // to UnknownRecord.
            var specific = ResourceRegistry.Create(Type);

            specific.Name  = Name;
            specific.Type  = Type;
            specific.Class = Class;
            specific.TTL   = TTL;

            // Read the specific properties of the resource record.
            var end = reader.Position + length;

            specific.ReadData(reader, length);
            if (reader.Position != end)
            {
                throw new InvalidDataException("Found extra data while decoding RDATA.");
            }

            return(specific);
        }
Example #2
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Algorithms.Clear();
     for (; length > 0; --length)
     {
         Algorithms.Add((DigestType)reader.ReadByte());
     }
 }
Example #3
0
        /// <inheritdoc />
        public override IWireSerialiser Read(WireReader reader)
        {
            Name  = reader.ReadDomainName();
            Type  = (DnsType)reader.ReadUInt16();
            Class = (DnsClass)reader.ReadUInt16();

            return(this);
        }
Example #4
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     while (length > 0)
     {
         var s = reader.ReadString();
         Strings.Add(s);
         length -= Encoding.UTF8.GetByteCount(s) + 1;
     }
 }
Example #5
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            HashAlgorithm = (DigestType)reader.ReadByte();
            Flags         = reader.ReadByte();
            Iterations    = reader.ReadUInt16();
            Salt          = reader.ReadByteLengthPrefixedBytes();
        }
Example #6
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            KeyTag        = reader.ReadUInt16();
            Algorithm     = (SecurityAlgorithm)reader.ReadByte();
            HashAlgorithm = (DigestType)reader.ReadByte();
            Digest        = reader.ReadBytes(end - reader.Position);
        }
Example #7
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            Flags     = (DNSKEYFlags)reader.ReadUInt16();
            Protocol  = reader.ReadByte();
            Algorithm = (SecurityAlgorithm)reader.ReadByte();
            PublicKey = reader.ReadBytes(end - reader.Position);
        }
Example #8
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            NextOwnerName = reader.ReadDomainName();
            while (reader.Position < end)
            {
                Types.AddRange(reader.ReadBitmap().Select(t => (DnsType)t));
            }
        }
Example #9
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();
 }
Example #10
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Algorithm         = reader.ReadDomainName();
     TimeSigned        = reader.ReadDateTime48();
     Fudge             = reader.ReadTimeSpan16();
     MAC               = reader.ReadUInt16LengthPrefixedBytes();
     OriginalMessageId = reader.ReadUInt16();
     Error             = (MessageStatus)reader.ReadUInt16();
     OtherData         = reader.ReadUInt16LengthPrefixedBytes();
 }
Example #11
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     PrimaryName  = reader.ReadDomainName();
     Mailbox      = reader.ReadDomainName();
     SerialNumber = reader.ReadUInt32();
     Refresh      = reader.ReadTimeSpan32();
     Retry        = reader.ReadTimeSpan32();
     Expire       = reader.ReadTimeSpan32();
     Minimum      = reader.ReadTimeSpan32();
 }
Example #12
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);
        }
Example #13
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            HashAlgorithm       = (DigestType)reader.ReadByte();
            Flags               = (NSEC3Flags)reader.ReadByte();
            Iterations          = reader.ReadUInt16();
            Salt                = reader.ReadByteLengthPrefixedBytes();
            NextHashedOwnerName = reader.ReadByteLengthPrefixedBytes();

            while (reader.Position < end)
            {
                Types.AddRange(reader.ReadBitmap().Select(t => (DnsType)t));
            }
        }
Example #14
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            switch (length)
            {
            case 0:
                Timeout = null;
                break;

            case 2:
                Timeout = TimeSpan.FromMilliseconds((int)reader.ReadUInt16() * 100);
                break;

            default:
                throw new InvalidDataException($"Invalid EdnsKeepAlive length of '{length}'.");
            }
        }
Example #15
0
        /// <inheritdoc />
        public override IWireSerialiser Read(WireReader reader)
        {
            Id = reader.ReadUInt16();
            var flags = reader.ReadUInt16();

            QR      = (flags & 0x8000) == 0x8000;
            AA      = (flags & 0x0400) == 0x0400;
            TC      = (flags & 0x0200) == 0x0200;
            RD      = (flags & 0x0100) == 0x0100;
            RA      = (flags & 0x0080) == 0x0080;
            opcode4 = (byte)((flags & 0x7800) >> 11);
            Z       = (flags & 0x0040) >> 6;
            AD      = (flags & 0x0020) == 0x0020;
            CD      = (flags & 0x0010) == 0x0010;
            Status  = (MessageStatus)(flags & 0x000F);
            var qdcount = reader.ReadUInt16();
            var ancount = reader.ReadUInt16();
            var nscount = reader.ReadUInt16();
            var arcount = reader.ReadUInt16();

            for (var i = 0; i < qdcount; ++i)
            {
                var question = (Question) new Question().Read(reader);
                Questions.Add(question);
            }
            for (var i = 0; i < ancount; ++i)
            {
                var rr = (ResourceRecord) new ResourceRecord().Read(reader);
                Answers.Add(rr);
            }
            for (var i = 0; i < nscount; ++i)
            {
                var rr = (ResourceRecord) new ResourceRecord().Read(reader);
                AuthorityRecords.Add(rr);
            }
            for (var i = 0; i < arcount; ++i)
            {
                var rr = (ResourceRecord) new ResourceRecord().Read(reader);
                AdditionalRecords.Add(rr);
            }

            return(this);
        }
Example #16
0
        /// <inheritdoc />
        public override IWireSerialiser Read(WireReader reader)
        {
            Id = reader.ReadUInt16();
            var flags = reader.ReadUInt16();

            QR     = (flags & 0x8000) == 0x8000;
            Opcode = (MessageOperation)((flags & 0x7800) >> 11);
            Z      = (flags & 0x07F0) >> 4;
            Status = (MessageStatus)(flags & 0x000F);
            var zocount = reader.ReadUInt16();
            var prcount = reader.ReadUInt16();
            var upcount = reader.ReadUInt16();
            var arcount = reader.ReadUInt16();

            for (var i = 0; i < zocount; ++i)
            {
                Zone = (Question) new Question().Read(reader);
            }
            for (var i = 0; i < prcount; ++i)
            {
                var rr = (ResourceRecord) new ResourceRecord().Read(reader);
                Prerequisites.Add(rr);
            }
            for (var i = 0; i < upcount; ++i)
            {
                var rr = (ResourceRecord) new ResourceRecord().Read(reader);
                Updates.Add(rr);
            }
            for (var i = 0; i < arcount; ++i)
            {
                var rr = (ResourceRecord) new ResourceRecord().Read(reader);
                AdditionalResources.Add(rr);
            }

            return(this);
        }
Example #17
0
        /// <inheritdoc />
        public override void ReadData(WireReader reader, int length)
        {
            var end = reader.Position + length;

            while (reader.Position < end)
            {
                var type    = (EdnsOptionType)reader.ReadUInt16();
                int olength = reader.ReadUInt16();

                EdnsOption option;
                if (EdnsOptionRegistry.Options.TryGetValue(type, out Func <EdnsOption> maker))
                {
                    option = maker();
                }
                else
                {
                    option = new UnknownEdnsOption {
                        Type = type
                    };
                }
                Options.Add(option);
                option.ReadData(reader, olength);
            }
        }
Example #18
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Address = reader.ReadIPAddress(length);
 }
Example #19
0
 /// <summary>
 ///   Read the data that is specific to the resource record <see cref="Type"/>.
 /// </summary>
 /// <param name="reader">
 ///   The source of the resource record's data.
 /// </param>
 /// <param name="length">
 ///   The length, in bytes, of the data.
 /// </param>
 /// <remarks>
 ///   Derived classes must implement this method.
 /// </remarks>
 public virtual void ReadData(WireReader reader, int length)
 {
 }
Example #20
0
 /// <inheritdoc />
 public override void ReadData(WireReader reader, int length)
 {
     Data = reader.ReadBytes(length);
 }
Example #21
0
 /// <inheritdoc />
 public abstract IWireSerialiser Read(WireReader reader);