Example #1
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;
        }
Example #2
0
 public void EccGost()
 {
     DigestRegistry.Create(SecurityAlgorithm.ECCGOST);
 }
Example #3
0
        public void RsaSha256()
        {
            var hasher = DigestRegistry.Create(SecurityAlgorithm.RSASHA256);

            Assert.IsInstanceOfType(hasher, typeof(HashAlgorithm));
        }
Example #4
0
 public void Gost()
 {
     DigestRegistry.Create(DigestType.GostR34_11_94);
 }
Example #5
0
        public void Sha256()
        {
            var hasher = DigestRegistry.Create(DigestType.Sha256);

            Assert.IsInstanceOfType(hasher, typeof(HashAlgorithm));
        }