Example #1
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (!isDisposed)
            {
                if (!(HmacK is null))
                {
                    HmacK.Dispose();
                }
                HmacK = null;

                isDisposed = true;
            }
        }
Example #2
0
        public void ComputeHash_WithKey_ExceptionTest()
        {
            HmacSha256 hmac = new HmacSha256();

            Exception ex = Assert.Throws <ArgumentNullException>(() => hmac.ComputeHash(null, new byte[1]));

            Assert.Contains("Data can not be null", ex.Message);

            ex = Assert.Throws <ArgumentNullException>(() => hmac.ComputeHash(new byte[1], null));
            Assert.Contains("Key can not be null", ex.Message);

            hmac.Dispose();
            ex = Assert.Throws <ObjectDisposedException>(() => hmac.ComputeHash(new byte[1], new byte[1]));
        }
Example #3
0
        /// <summary>
        /// Releases the resources used by the <see cref="Rfc6979"/> class.
        /// </summary>
        /// <param name="disposing">
        /// True to release both managed and unmanaged resources; false to release only unmanaged resources.
        /// </param>
        protected virtual void Dispose(bool disposing)
        {
            if (!isDisposed)
            {
                if (disposing)
                {
                    if (!(HmacK is null))
                    {
                        HmacK.Dispose();
                    }
                    HmacK = null;
                }

                isDisposed = true;
            }
        }
Example #4
0
        public void ComputeHash_ExceptionTest()
        {
            HmacSha256 hmac = new HmacSha256();

            Exception ex = Assert.Throws <ArgumentNullException>(() => hmac.ComputeHash(null));

            Assert.Contains("Data can not be null", ex.Message);

            ex = Assert.Throws <ArgumentNullException>(() => hmac.ComputeHash(new byte[1]));
            Assert.Contains("Key must be set before calling this function", ex.Message);

            hmac.Key = new byte[1];
            ex       = Assert.Throws <ArgumentNullException>(() => hmac.ComputeHash(null));
            Assert.Contains("Data can not be null", ex.Message);

            hmac.Dispose();
            ex = Assert.Throws <ObjectDisposedException>(() => hmac.ComputeHash(new byte[1]));
        }