< Summary

Information
Class: Renci.SshNet.Security.Cryptography.RsaDigitalSignature
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\RsaDigitalSignature.cs
Line coverage
93%
Covered lines: 31
Uncovered lines: 2
Coverable lines: 33
Total lines: 96
Line coverage: 93.9%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
.ctor(...)50%2100%
Hash(...)100%1100%
Dispose()100%1100%
Dispose(...)83.33%686.66%
Finalize()100%1100%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\RsaDigitalSignature.cs

#LineLine coverage
 1using System;
 2using System.Security.Cryptography;
 3using Renci.SshNet.Common;
 4using Renci.SshNet.Security.Cryptography.Ciphers;
 5
 6namespace Renci.SshNet.Security.Cryptography
 7{
 8    /// <summary>
 9    /// Implements RSA digital signature algorithm.
 10    /// </summary>
 11    public class RsaDigitalSignature : CipherDigitalSignature, IDisposable
 12    {
 13        private HashAlgorithm _hash;
 14
 15        /// <summary>
 16        /// Initializes a new instance of the <see cref="RsaDigitalSignature"/> class with the SHA-1 hash algorithm.
 17        /// </summary>
 18        /// <param name="rsaKey">The RSA key.</param>
 19        public RsaDigitalSignature(RsaKey rsaKey)
 52320            : this(rsaKey, HashAlgorithmName.SHA1)
 52321        {
 52322        }
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="RsaDigitalSignature"/> class.
 26        /// </summary>
 27        /// <param name="rsaKey">The RSA key.</param>
 28        /// <param name="hashAlgorithmName">The hash algorithm to use in the digital signature.</param>
 29        public RsaDigitalSignature(RsaKey rsaKey, HashAlgorithmName hashAlgorithmName)
 277130            : base(ObjectIdentifier.FromHashAlgorithmName(hashAlgorithmName), new RsaCipher(rsaKey))
 276831        {
 276832            _hash = CryptoConfig.CreateFromName(hashAlgorithmName.Name) as HashAlgorithm
 276833                ?? throw new ArgumentException($"Could not create {nameof(HashAlgorithm)} from `{hashAlgorithmName}`.", 
 276834        }
 35
 36        /// <summary>
 37        /// Hashes the specified input.
 38        /// </summary>
 39        /// <param name="input">The input.</param>
 40        /// <returns>
 41        /// Hashed data.
 42        /// </returns>
 43        protected override byte[] Hash(byte[] input)
 190644        {
 190645            return _hash.ComputeHash(input);
 190646        }
 47
 48        #region IDisposable Members
 49
 50        private bool _isDisposed;
 51
 52        /// <summary>
 53        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 54        /// </summary>
 55        public void Dispose()
 356        {
 357            Dispose(disposing: true);
 358            GC.SuppressFinalize(this);
 359        }
 60
 61        /// <summary>
 62        /// Releases unmanaged and - optionally - managed resources.
 63        /// </summary>
 64        /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langwor
 65        protected virtual void Dispose(bool disposing)
 277066        {
 277067            if (_isDisposed)
 068            {
 069                return;
 70            }
 71
 277072            if (disposing)
 373            {
 374                var hash = _hash;
 375                if (hash != null)
 376                {
 377                    hash.Dispose();
 378                    _hash = null;
 379                }
 80
 381                _isDisposed = true;
 382            }
 277083        }
 84
 85        /// <summary>
 86        /// Releases unmanaged resources and performs other cleanup operations before the
 87        /// <see cref="RsaDigitalSignature"/> is reclaimed by garbage collection.
 88        /// </summary>
 89        ~RsaDigitalSignature()
 553490        {
 276791            Dispose(disposing: false);
 553492        }
 93
 94        #endregion
 95    }
 96}