< Summary

Information
Class: Renci.SshNet.Security.DsaKey
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\DsaKey.cs
Line coverage
65%
Covered lines: 44
Uncovered lines: 23
Coverable lines: 67
Total lines: 194
Line coverage: 65.6%
Branch coverage
41%
Covered branches: 5
Total branches: 12
Branch coverage: 41.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_P()100%1100%
get_Q()100%1100%
get_G()100%1100%
get_Y()100%1100%
get_X()100%1100%
get_KeyLength()100%1100%
get_DigitalSignature()100%2100%
get_Public()100%1100%
set_Public(...)50%266.66%
.ctor()100%1100%
.ctor(...)0%20%
.ctor(...)100%1100%
Dispose()100%10%
Dispose(...)33.33%626.66%
Finalize()100%1100%

File(s)

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

#LineLine coverage
 1using System;
 2using Renci.SshNet.Common;
 3using Renci.SshNet.Security.Cryptography;
 4
 5namespace Renci.SshNet.Security
 6{
 7    /// <summary>
 8    /// Contains DSA private and public key.
 9    /// </summary>
 10    public class DsaKey : Key, IDisposable
 11    {
 12        private DsaDigitalSignature _digitalSignature;
 13        private bool _isDisposed;
 14
 15        /// <summary>
 16        /// Gets the P.
 17        /// </summary>
 18        public BigInteger P
 19        {
 20            get
 1721            {
 1722                return _privateKey[0];
 1723            }
 24        }
 25
 26        /// <summary>
 27        /// Gets the Q.
 28        /// </summary>
 29        public BigInteger Q
 30        {
 31            get
 2832            {
 2833                return _privateKey[1];
 2834            }
 35        }
 36
 37        /// <summary>
 38        /// Gets the G.
 39        /// </summary>
 40        public BigInteger G
 41        {
 42            get
 843            {
 844                return _privateKey[2];
 845            }
 46        }
 47
 48        /// <summary>
 49        /// Gets public key Y.
 50        /// </summary>
 51        public BigInteger Y
 52        {
 53            get
 754            {
 755                return _privateKey[3];
 756            }
 57        }
 58
 59        /// <summary>
 60        /// Gets private key X.
 61        /// </summary>
 62        public BigInteger X
 63        {
 64            get
 165            {
 166                return _privateKey[4];
 167            }
 68        }
 69
 70        /// <summary>
 71        /// Gets the length of the key.
 72        /// </summary>
 73        /// <value>
 74        /// The length of the key.
 75        /// </value>
 76        public override int KeyLength
 77        {
 78            get
 379            {
 380                return P.BitLength;
 381            }
 82        }
 83
 84        /// <summary>
 85        /// Gets the digital signature.
 86        /// </summary>
 87        protected internal override DigitalSignature DigitalSignature
 88        {
 89            get
 1690            {
 1691                _digitalSignature ??= new DsaDigitalSignature(this);
 1692                return _digitalSignature;
 1693            }
 94        }
 95
 96        /// <summary>
 97        /// Gets or sets the public.
 98        /// </summary>
 99        /// <value>
 100        /// The public.
 101        /// </value>
 102        public override BigInteger[] Public
 103        {
 104            get
 4105            {
 4106                return new[] { P, Q, G, Y };
 4107            }
 108            set
 3109            {
 3110                if (value.Length != 4)
 0111                {
 0112                    throw new InvalidOperationException("Invalid public key.");
 113                }
 114
 3115                _privateKey = value;
 3116            }
 117        }
 118
 119        /// <summary>
 120        /// Initializes a new instance of the <see cref="DsaKey"/> class.
 121        /// </summary>
 3122        public DsaKey()
 3123        {
 3124            _privateKey = new BigInteger[5];
 3125        }
 126
 127        /// <summary>
 128        /// Initializes a new instance of the <see cref="DsaKey"/> class.
 129        /// </summary>
 130        /// <param name="data">DER encoded private key data.</param>
 131        public DsaKey(byte[] data)
 0132            : base(data)
 0133        {
 0134            if (_privateKey.Length != 5)
 0135            {
 0136                throw new InvalidOperationException("Invalid private key.");
 137            }
 0138        }
 139
 140        /// <summary>
 141        /// Initializes a new instance of the <see cref="DsaKey" /> class.
 142        /// </summary>
 143        /// <param name="p">The p.</param>
 144        /// <param name="q">The q.</param>
 145        /// <param name="g">The g.</param>
 146        /// <param name="y">The y.</param>
 147        /// <param name="x">The x.</param>
 13148        public DsaKey(BigInteger p, BigInteger q, BigInteger g, BigInteger y, BigInteger x)
 13149        {
 13150            _privateKey = new BigInteger[5] { p, q, g, y, x };
 13151        }
 152
 153        /// <summary>
 154        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 155        /// </summary>
 156        public void Dispose()
 0157        {
 0158            Dispose(disposing: true);
 0159            GC.SuppressFinalize(this);
 0160        }
 161
 162        /// <summary>
 163        /// Releases unmanaged and - optionally - managed resources.
 164        /// </summary>
 165        /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langwor
 166        protected virtual void Dispose(bool disposing)
 16167        {
 16168            if (_isDisposed)
 0169            {
 0170                return;
 171            }
 172
 16173            if (disposing)
 0174            {
 0175                var digitalSignature = _digitalSignature;
 0176                if (digitalSignature != null)
 0177                {
 0178                    digitalSignature.Dispose();
 0179                    _digitalSignature = null;
 0180                }
 181
 0182                _isDisposed = true;
 0183            }
 16184        }
 185
 186        /// <summary>
 187        /// Finalizes an instance of the <see cref="DsaKey"/> class.
 188        /// </summary>
 189        ~DsaKey()
 32190        {
 16191            Dispose(disposing: false);
 32192        }
 193    }
 194}