internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < ConstantPartLength + DnsDomainName.RootLength)
            {
                return(null);
            }

            DnsDomainName algorithm;
            int           algorithmLength;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length - ConstantPartLength, out algorithm, out algorithmLength))
            {
                return(null);
            }
            offsetInDns += algorithmLength;
            length      -= algorithmLength;

            if (length < ConstantPartLength)
            {
                return(null);
            }

            UInt48 timeSigned = dns.ReadUInt48(offsetInDns + OffsetAfterAlgorithm.TimeSigned, Endianity.Big);
            ushort fudge      = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.Fudge, Endianity.Big);
            int    messageAuthenticationCodeLength = dns.ReadUShort(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCodeSize, Endianity.Big);

            if (length < ConstantPartLength + messageAuthenticationCodeLength)
            {
                return(null);
            }
            DataSegment messageAuthenticationCode = dns.Subsegment(offsetInDns + OffsetAfterAlgorithm.MessageAuthenticationCode, messageAuthenticationCodeLength);
            int         totalReadAfterAlgorithm   = OffsetAfterAlgorithm.MessageAuthenticationCode + messageAuthenticationCodeLength;

            offsetInDns += totalReadAfterAlgorithm;
            length      -= totalReadAfterAlgorithm;

            ushort          originalId  = dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.OriginalId, Endianity.Big);
            DnsResponseCode error       = (DnsResponseCode)dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.Error, Endianity.Big);
            int             otherLength = dns.ReadUShort(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherLength, Endianity.Big);

            if (length != OffsetAfterMessageAuthenticationCode.OtherData + otherLength)
            {
                return(null);
            }
            DataSegment other = dns.Subsegment(offsetInDns + OffsetAfterMessageAuthenticationCode.OtherData, otherLength);

            return(new DnsResourceDataTransactionSignature(algorithm, timeSigned, fudge, messageAuthenticationCode, originalId, error, other));
        }
Esempio n. 2
0
        internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length)
        {
            if (length < 17)
            {
                return((DnsResourceData)null);
            }
            DnsDomainName domainName;
            int           numBytesRead;

            if (!DnsDomainName.TryParse(dns, offsetInDns, length - 16, out domainName, out numBytesRead))
            {
                return((DnsResourceData)null);
            }
            offsetInDns += numBytesRead;
            length      -= numBytesRead;
            if (length < 16)
            {
                return((DnsResourceData)null);
            }
            UInt48 timeSigned = dns.ReadUInt48(offsetInDns, Endianity.Big);
            ushort fudge      = dns.ReadUShort(offsetInDns + 6, Endianity.Big);
            int    length1    = (int)dns.ReadUShort(offsetInDns + 8, Endianity.Big);

            if (length < 16 + length1)
            {
                return((DnsResourceData)null);
            }
            DataSegment messageAuthenticationCode = dns.Subsegment(offsetInDns + 10, length1);
            int         num = 10 + length1;

            offsetInDns += num;
            length      -= num;
            ushort          originalId = dns.ReadUShort(offsetInDns, Endianity.Big);
            DnsResponseCode error      = (DnsResponseCode)dns.ReadUShort(offsetInDns + 2, Endianity.Big);
            int             length2    = (int)dns.ReadUShort(offsetInDns + 4, Endianity.Big);

            if (length != 6 + length2)
            {
                return((DnsResourceData)null);
            }
            DataSegment other = dns.Subsegment(offsetInDns + 6, length2);

            return((DnsResourceData) new DnsResourceDataTransactionSignature(domainName, timeSigned, fudge, messageAuthenticationCode, originalId, error, other));
        }