/// <summary> /// Constructs an instance out of the key tag, algorithm, digest type and digest fields. /// </summary> /// <param name="keyTag"> /// Lists the key tag of the DNSKEY RR referred to by the DS record. /// The Key Tag used by the DS RR is identical to the Key Tag used by RRSIG RRs. /// Calculated as specified in RFC 2535. /// </param> /// <param name="algorithm">Algorithm must be allowed to sign DNS data.</param> /// <param name="digestType">An identifier for the digest algorithm used.</param> /// <param name="digest"> /// Calculated over the canonical name of the delegated domain name followed by the whole RDATA of the KEY record (all four fields). /// digest = hash(canonical FQDN on KEY RR | KEY_RR_rdata) /// KEY_RR_rdata = Flags | Protocol | Algorithm | Public Key /// The size of the digest may vary depending on the digest type. /// </param> public DnsResourceDataDelegationSigner(ushort keyTag, DnsAlgorithm algorithm, DnsDigestType digestType, DataSegment digest) { if (digest == null) { throw new ArgumentNullException("digest"); } KeyTag = keyTag; Algorithm = algorithm; DigestType = digestType; int maxDigestLength; switch (DigestType) { case DnsDigestType.Sha1: maxDigestLength = 20; break; case DnsDigestType.Sha256: maxDigestLength = 32; break; default: maxDigestLength = int.MaxValue; break; } Digest = digest.Subsegment(0, Math.Min(digest.Length, maxDigestLength)); ExtraDigest = digest.Subsegment(Digest.Length, digest.Length - Digest.Length); }
internal override DnsResourceData CreateInstance(DataSegment data) { ushort keyTag = data.ReadUShort(Offset.KeyTag, Endianity.Big); DnsAlgorithm algorithm = (DnsAlgorithm)data[Offset.Algorithm]; DnsDigestType digestType = (DnsDigestType)data[Offset.DigestType]; DataSegment digest = data.Subsegment(Offset.Digest, data.Length - ConstPartLength); return(new DnsResourceDataDelegationSigner(keyTag, algorithm, digestType, digest)); }
public DnsResourceDataDelegationSigner(ushort keyTag, DnsAlgorithm algorithm, DnsDigestType digestType, DataSegment digest) { if (digest == null) { throw new ArgumentNullException("digest"); } this.KeyTag = keyTag; this.Algorithm = algorithm; this.DigestType = digestType; int val2; switch (this.DigestType) { case DnsDigestType.Sha1: val2 = 20; break; case DnsDigestType.Sha256: val2 = 32; break; default: val2 = int.MaxValue; break; } this.Digest = digest.Subsegment(0, Math.Min(digest.Length, val2)); this.ExtraDigest = digest.Subsegment(this.Digest.Length, digest.Length - this.Digest.Length); }