Exemplo n.º 1
0
        public void ToHashSizeInBytes()
        {
            foreach (HashAlgorithmName name in this.GetNames())
            {
                int           size      = HashAlgorithmConvertor.ToHashSizeInBytes(name);
                HashAlgorithm algorithm = HashAlgorithmConvertor.ToHashAlgorithm(name);

                Assert.AreEqual(algorithm.HashSize / 8, size);
            }
        }
Exemplo n.º 2
0
        private static void ConstructAsn1(HashAlgorithmName hashAlgorithmName, ReadOnlySpan <byte> digest, AsnWriter asnWriter)
        {
            string oid  = HashAlgorithmConvertor.ToOid(hashAlgorithmName);
            int    size = HashAlgorithmConvertor.ToHashSizeInBytes(hashAlgorithmName);

            if (digest.Length != size)
            {
                throw new ArgumentOutOfRangeException(nameof(digest), $"digest has bad length. Expected size of {hashAlgorithmName.Name} digest is {size}B, actual length is {digest.Length}.");
            }

            // Digest info
            asnWriter.PushSequence();

            // AlgorithmIdetifier
            asnWriter.PushSequence();
            asnWriter.WriteObjectIdentifier(oid);
            asnWriter.WriteNull();
            asnWriter.PopSequence();

            asnWriter.WriteOctetString(digest);
            asnWriter.PopSequence();
        }