public DnsResourceDataHostIdentityProtocol(DataSegment hostIdentityTag, DnsPublicKeyAlgorithm publicKeyAlgorithm, DataSegment publicKey, IEnumerable <DnsDomainName> rendezvousServers) { if (hostIdentityTag == null) { throw new ArgumentNullException("hostIdentityTag"); } if (publicKey == null) { throw new ArgumentNullException("publicKey"); } if (hostIdentityTag.Length > (int)byte.MaxValue) { throw new ArgumentOutOfRangeException("hostIdentityTag", (object)hostIdentityTag.Length, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Cannot be bigger than {0}.", new object[1] { (object)byte.MaxValue })); } if (publicKey.Length > (int)ushort.MaxValue) { throw new ArgumentOutOfRangeException("publicKey", (object)publicKey.Length, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Cannot be bigger than {0}.", new object[1] { (object)ushort.MaxValue })); } this.HostIdentityTag = hostIdentityTag; this.PublicKeyAlgorithm = publicKeyAlgorithm; this.PublicKey = publicKey; this.RendezvousServers = IListExtensions.AsReadOnly <DnsDomainName>((IList <DnsDomainName>)Enumerable.ToArray <DnsDomainName>(rendezvousServers)); }
/// <summary> /// Constructs an instance out of the precedence, gateway, algorithm and public key fields. /// </summary> /// <param name="precedence"> /// Precedence for this record. /// Gateways listed in IPSECKEY records with lower precedence are to be attempted first. /// Where there is a tie in precedence, the order should be non-deterministic. /// </param> /// <param name="gateway"> /// Indicates a gateway to which an IPsec tunnel may be created in order to reach the entity named by this /// resource record. /// </param> /// <param name="algorithm">Identifies the public key's cryptographic algorithm and determines the format of the public key field.</param> /// <param name="publicKey">Contains the algorithm-specific portion of the KEY RR RDATA.</param> public DnsResourceDataIpSecKey(byte precedence, DnsGateway gateway, DnsPublicKeyAlgorithm algorithm, DataSegment publicKey) { Precedence = precedence; Gateway = gateway; Algorithm = algorithm; PublicKey = publicKey; }
/// <summary> /// Constructs an instance out of the host identity tag, public key algorithm, public key and rendezvous servers fields. /// </summary> /// <param name="hostIdentityTag">Stored as a binary value in network byte order.</param> /// <param name="publicKeyAlgorithm">Identifies the public key's cryptographic algorithm and determines the format of the public key field.</param> /// <param name="publicKey">Contains the algorithm-specific portion of the KEY RR RDATA.</param> /// <param name="rendezvousServers"> /// Indicates one or more domain names of rendezvous server(s). /// Must not be compressed. /// The rendezvous server(s) are listed in order of preference (i.e., first rendezvous server(s) are preferred), /// defining an implicit order amongst rendezvous servers of a single RR. /// When multiple HIP RRs are present at the same owner name, /// this implicit order of rendezvous servers within an RR must not be used to infer a preference order between rendezvous servers stored in different RRs. /// </param> public DnsResourceDataHostIdentityProtocol(DataSegment hostIdentityTag, DnsPublicKeyAlgorithm publicKeyAlgorithm, DataSegment publicKey, IEnumerable <DnsDomainName> rendezvousServers) { if (hostIdentityTag == null) { throw new ArgumentNullException("hostIdentityTag"); } if (publicKey == null) { throw new ArgumentNullException("publicKey"); } if (hostIdentityTag.Length > byte.MaxValue) { throw new ArgumentOutOfRangeException("hostIdentityTag", hostIdentityTag.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be bigger than {0}.", byte.MaxValue)); } if (publicKey.Length > ushort.MaxValue) { throw new ArgumentOutOfRangeException("publicKey", publicKey.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be bigger than {0}.", ushort.MaxValue)); } HostIdentityTag = hostIdentityTag; PublicKeyAlgorithm = publicKeyAlgorithm; PublicKey = publicKey; RendezvousServers = IListExtensions.AsReadOnly <DnsDomainName>(rendezvousServers.ToArray()); }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < 3) { return((DnsResourceData)null); } byte precedence = dns[offsetInDns]; DnsGatewayType gatewayType = (DnsGatewayType)dns[offsetInDns + 1]; DnsPublicKeyAlgorithm algorithm = (DnsPublicKeyAlgorithm)dns[offsetInDns + 2]; DnsGateway instance = DnsGateway.CreateInstance(gatewayType, dns, offsetInDns + 3, length - 3); if (instance == null) { return((DnsResourceData)null); } DataSegment publicKey = dns.Subsegment(offsetInDns + 3 + instance.Length, length - 3 - instance.Length); return((DnsResourceData) new DnsResourceDataIpSecKey(precedence, instance, algorithm, publicKey)); }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < ConstPartLength) { return(null); } byte precedence = dns[offsetInDns + Offset.Precedence]; DnsGatewayType gatewayType = (DnsGatewayType)dns[offsetInDns + Offset.GatewayType]; DnsPublicKeyAlgorithm algorithm = (DnsPublicKeyAlgorithm)dns[offsetInDns + Offset.Algorithm]; DnsGateway gateway = DnsGateway.CreateInstance(gatewayType, dns, offsetInDns + Offset.Gateway, length - ConstPartLength); if (gateway == null) { return(null); } DataSegment publicKey = dns.Subsegment(offsetInDns + ConstPartLength + gateway.Length, length - ConstPartLength - gateway.Length); return(new DnsResourceDataIpSecKey(precedence, gateway, algorithm, publicKey)); }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < ConstantPartLength) { return(null); } int hostIdentityTagLength = dns[offsetInDns + Offset.HostIdentityTagLength]; DnsPublicKeyAlgorithm publicKeyAlgorithm = (DnsPublicKeyAlgorithm)dns[offsetInDns + Offset.PublicKeyAlgorithm]; int publicKeyLength = dns.ReadUShort(offsetInDns + Offset.PublicKeyLength, Endianity.Big); if (length < ConstantPartLength + hostIdentityTagLength + publicKeyLength) { return(null); } DataSegment hostIdentityTag = dns.Subsegment(offsetInDns + Offset.HostIdentityTag, hostIdentityTagLength); int publicKeyOffset = offsetInDns + ConstantPartLength + hostIdentityTagLength; DataSegment publicKey = dns.Subsegment(publicKeyOffset, publicKeyLength); offsetInDns += ConstantPartLength + hostIdentityTagLength + publicKeyLength; length -= ConstantPartLength + hostIdentityTagLength + publicKeyLength; List <DnsDomainName> rendezvousServers = new List <DnsDomainName>(); while (length != 0) { DnsDomainName rendezvousServer; int rendezvousServerLength; if (!DnsDomainName.TryParse(dns, offsetInDns, length, out rendezvousServer, out rendezvousServerLength)) { return(null); } rendezvousServers.Add(rendezvousServer); offsetInDns += rendezvousServerLength; length -= rendezvousServerLength; } return(new DnsResourceDataHostIdentityProtocol(hostIdentityTag, publicKeyAlgorithm, publicKey, rendezvousServers)); }
internal override DnsResourceData CreateInstance(DnsDatagram dns, int offsetInDns, int length) { if (length < 4) { return((DnsResourceData)null); } int length1 = (int)dns[offsetInDns]; DnsPublicKeyAlgorithm publicKeyAlgorithm = (DnsPublicKeyAlgorithm)dns[offsetInDns + 1]; int length2 = (int)dns.ReadUShort(offsetInDns + 2, Endianity.Big); if (length < 4 + length1 + length2) { return((DnsResourceData)null); } DataSegment hostIdentityTag = dns.Subsegment(offsetInDns + 4, length1); int offset = offsetInDns + 4 + length1; DataSegment publicKey = dns.Subsegment(offset, length2); offsetInDns += 4 + length1 + length2; length -= 4 + length1 + length2; List <DnsDomainName> list = new List <DnsDomainName>(); while (length != 0) { DnsDomainName domainName; int numBytesRead; if (!DnsDomainName.TryParse(dns, offsetInDns, length, out domainName, out numBytesRead)) { return((DnsResourceData)null); } list.Add(domainName); offsetInDns += numBytesRead; length -= numBytesRead; } return((DnsResourceData) new DnsResourceDataHostIdentityProtocol(hostIdentityTag, publicKeyAlgorithm, publicKey, (IEnumerable <DnsDomainName>)list)); }