예제 #1
0
        /// <inheritdoc />
        public override void Write(WireWriter writer)
        {
            writer.WriteUInt16(Id);
            var flags =
                (Convert.ToInt32(QR) << 15) |
                (((ushort)Opcode & 0xf) << 11) |
                ((Z & 0x7F) << 4) |
                ((ushort)Status & 0xf);

            writer.WriteUInt16((ushort)flags);
            writer.WriteUInt16((ushort)1);
            writer.WriteUInt16((ushort)Prerequisites.Count);
            writer.WriteUInt16((ushort)Updates.Count);
            writer.WriteUInt16((ushort)AdditionalResources.Count);
            Zone.Write(writer);
            foreach (var r in Prerequisites)
            {
                r.Write(writer);
            }
            foreach (var r in Updates)
            {
                r.Write(writer);
            }
            foreach (var r in AdditionalResources)
            {
                r.Write(writer);
            }
        }
예제 #2
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteUInt16(KeyTag);
     writer.WriteByte((byte)Algorithm);
     writer.WriteByte((byte)HashAlgorithm);
     writer.WriteBytes(Digest);
 }
예제 #3
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     foreach (var algorithm in Algorithms)
     {
         writer.WriteByte((byte)algorithm);
     }
 }
예제 #4
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteUInt16((ushort)Flags);
     writer.WriteByte(Protocol);
     writer.WriteByte((byte)Algorithm);
     writer.WriteBytes(PublicKey);
 }
예제 #5
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteByte((byte)HashAlgorithm);
     writer.WriteByte(Flags);
     writer.WriteUInt16(Iterations);
     writer.WriteByteLengthPrefixedBytes(Salt);
 }
예제 #6
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     if (Timeout.HasValue)
     {
         writer.WriteUInt16((ushort)(Timeout.Value.TotalMilliseconds / 100));
     }
 }
예제 #7
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     foreach (var s in Strings)
     {
         writer.WriteString(s);
     }
 }
예제 #8
0
        /// <summary>
        ///   Length in bytes of the object when serialised.
        /// </summary>
        /// <returns>
        ///   Numbers of bytes when serialised.
        /// </returns>
        public int Length()
        {
            var writer = new WireWriter(Stream.Null);

            Write(writer);

            return(writer.Position);
        }
예제 #9
0
 /// <summary>
 ///   The resource specific data.
 /// </summary>
 /// <returns>
 ///   A byte array, never <b>null</b>.
 /// </returns>
 /// <remarks>
 ///   This is referred to as the <c>RDATA</c> in the DNS spec.
 /// </remarks>
 public byte[] GetData()
 {
     using (var ms = new MemoryStream())
     {
         var writer = new WireWriter(ms);
         this.WriteData(writer);
         return(ms.ToArray());
     }
 }
예제 #10
0
 /// <summary>
 ///   The length of the resource specific data.
 /// </summary>
 /// <returns>
 ///   Number of bytes to represent the resource specific data.
 /// </returns>
 /// <remarks>
 ///   This is referred to as the <c>RDLENGTH</c> in the DNS spec.
 /// </remarks>
 public int GetDataLength()
 {
     using (var ms = new MemoryStream())
     {
         var writer = new WireWriter(ms);
         this.WriteData(writer);
         return((int)ms.Length);
     }
 }
예제 #11
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteByte((byte)HashAlgorithm);
     writer.WriteByte((byte)Flags);
     writer.WriteUInt16(Iterations);
     writer.WriteByteLengthPrefixedBytes(Salt);
     writer.WriteByteLengthPrefixedBytes(NextHashedOwnerName);
     writer.WriteBitmap(Types.Select(t => (ushort)t));
 }
예제 #12
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteDomainName(PrimaryName);
     writer.WriteDomainName(Mailbox);
     writer.WriteUInt32(SerialNumber);
     writer.WriteTimeSpan32(Refresh);
     writer.WriteTimeSpan32(Retry);
     writer.WriteTimeSpan32(Expire);
     writer.WriteTimeSpan32(Minimum);
 }
예제 #13
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteDomainName(Algorithm);
     writer.WriteDateTime32(Inception);
     writer.WriteDateTime32(Expiration);
     writer.WriteUInt16((ushort)Mode);
     writer.WriteUInt16((ushort)Error);
     writer.WriteUint16LengthPrefixedBytes(Key);
     writer.WriteUint16LengthPrefixedBytes(OtherData);
 }
예제 #14
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteDomainName(Algorithm);
     writer.WriteDateTime48(TimeSigned);
     writer.WriteTimeSpan16(Fudge);
     writer.WriteUint16LengthPrefixedBytes(MAC);
     writer.WriteUInt16(OriginalMessageId);
     writer.WriteUInt16((ushort)Error);
     writer.WriteUint16LengthPrefixedBytes(OtherData);
 }
예제 #15
0
        /// <inheritdoc />
        public override void WriteData(WireWriter writer)
        {
            foreach (var option in Options)
            {
                writer.WriteUInt16((ushort)option.Type);

                writer.PushLengthPrefixedScope();
                option.WriteData(writer);
                writer.PopLengthPrefixedScope();
            }
        }
예제 #16
0
        /// <inheritdoc />
        public override void Write(WireWriter writer)
        {
            writer.WriteDomainName(Name);
            writer.WriteUInt16((ushort)Type);
            writer.WriteUInt16((ushort)Class);
            writer.WriteTimeSpan32(TTL);

            writer.PushLengthPrefixedScope();
            WriteData(writer);
            writer.PopLengthPrefixedScope();
        }
예제 #17
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteUInt16((ushort)TypeCovered);
     writer.WriteByte((byte)Algorithm);
     writer.WriteByte(Labels);
     writer.WriteTimeSpan32(OriginalTTL);
     writer.WriteDateTime32(SignatureExpiration);
     writer.WriteDateTime32(SignatureInception);
     writer.WriteUInt16(KeyTag);
     writer.WriteDomainName(SignerName, uncompressed: true);
     writer.WriteBytes(Signature);
 }
예제 #18
0
        /// <inheritdoc />
        public override void Write(WireWriter writer)
        {
            writer.WriteDomainName(Name);
            writer.WriteUInt16((ushort)Type);

            var classValue = (ushort)Class;

            if (QU)
            {
                classValue = (ushort)(classValue | 0x01 << 15);
            }

            writer.WriteUInt16((ushort)classValue);
        }
예제 #19
0
        /// <inheritdoc />
        public override void Write(WireWriter writer)
        {
            writer.WriteUInt16(Id);
            var flags =
                (Convert.ToInt32(QR) << 15) |
                (((ushort)opcode4 & 0xf) << 11) |
                (Convert.ToInt32(AA) << 10) |
                (Convert.ToInt32(TC) << 9) |
                (Convert.ToInt32(RD) << 8) |
                (Convert.ToInt32(RA) << 7) |
                ((Z & 0x1) << 6) |
                (Convert.ToInt32(AD) << 5) |
                (Convert.ToInt32(CD) << 4) |
                ((ushort)Status & 0xf);

            writer.WriteUInt16((ushort)flags);
            writer.WriteUInt16((ushort)Questions.Count);
            writer.WriteUInt16((ushort)Answers.Count);
            writer.WriteUInt16((ushort)AuthorityRecords.Count);
            writer.WriteUInt16((ushort)AdditionalRecords.Count);
            foreach (var r in Questions)
            {
                r.Write(writer);
            }
            foreach (var r in Answers)
            {
                r.Write(writer);
            }
            foreach (var r in AuthorityRecords)
            {
                r.Write(writer);
            }
            foreach (var r in AdditionalRecords)
            {
                r.Write(writer);
            }
        }
예제 #20
0
        /// <summary>
        ///   Creates a new instance of the <see cref="DSRecord"/> class
        ///   from the specified <see cref="DNSKEYRecord"/>.
        /// </summary>
        /// <param name="key">
        ///   The dns key to use.
        /// </param>
        /// <param name="force">
        ///   If <b>true</b>, key usage checks are ignored.
        /// </param>
        /// <exception cref="ArgumentException">
        ///   Both <see cref="DNSKEYFlags.ZoneKey"/> and <see cref="DNSKEYFlags.SecureEntryPoint"/>
        ///   must be set.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///   The <see cref="ResourceRecord.Name"/> of the <paramref name="key"/> is missing.
        /// </exception>
        public DSRecord(DNSKEYRecord key, bool force = false)
            : this()
        {
            // Check the key.
            if (!force)
            {
                if ((key.Flags & DNSKEYFlags.ZoneKey) == DNSKEYFlags.None)
                {
                    throw new ArgumentException("ZoneKey must be set.", "key");
                }
                if ((key.Flags & DNSKEYFlags.SecureEntryPoint) == DNSKEYFlags.None)
                {
                    throw new ArgumentException("SecureEntryPoint must be set.", "key");
                }
            }

            byte[] digest;
            using (var ms = new MemoryStream())
                using (var hasher = DigestRegistry.Create(key.Algorithm))
                {
                    var writer = new WireWriter(ms)
                    {
                        CanonicalForm = true
                    };
                    writer.WriteDomainName(key.Name);
                    key.WriteData(writer);
                    ms.Position = 0;
                    digest      = hasher.ComputeHash(ms);
                }
            Algorithm     = key.Algorithm;
            Class         = key.Class;
            KeyTag        = key.KeyTag();
            Name          = key.Name;
            TTL           = key.TTL;
            Digest        = digest;
            HashAlgorithm = DigestType.Sha1;
        }
예제 #21
0
 /// <inheritdoc />
 public abstract void Write(WireWriter writer);
예제 #22
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteIPAddress(Address);
 }
예제 #23
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteBytes(Data);
 }
예제 #24
0
 /// <inheritdoc />
 public override void WriteData(WireWriter writer)
 {
     writer.WriteDomainName(NextOwnerName, uncompressed: true);
     writer.WriteBitmap(Types.Select(t => (ushort)t));
 }
예제 #25
0
 /// <summary>
 ///   Write the data that is specific to the resource record <see cref="System.Type"/>.
 /// </summary>
 /// <param name="writer">
 ///   The destination for the DNS object's data.
 /// </param>
 /// <remarks>
 ///   Derived classes must implement this method.
 /// </remarks>
 public virtual void WriteData(WireWriter writer)
 {
 }