< Summary

Information
Class: Renci.SshNet.Security.ED25519Key
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\ED25519Key.cs
Line coverage
75%
Covered lines: 41
Uncovered lines: 13
Coverable lines: 54
Total lines: 163
Line coverage: 75.9%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor()100%1100%
ToString()100%1100%
get_Public()100%1100%
set_Public(...)100%1100%
get_KeyLength()100%1100%
get_DigitalSignature()100%2100%
get_PublicKey()100%1100%
get_PrivateKey()100%1100%
.ctor(...)100%10%
.ctor(...)100%1100%
Dispose()100%10%
Dispose(...)50%444.44%
Finalize()100%1100%

File(s)

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

#LineLine coverage
 1using System;
 2
 3using Renci.SshNet.Common;
 4using Renci.SshNet.Security.Chaos.NaCl;
 5using Renci.SshNet.Security.Cryptography;
 6
 7namespace Renci.SshNet.Security
 8{
 9    /// <summary>
 10    /// Contains ED25519 private and public key.
 11    /// </summary>
 12    public class ED25519Key : Key, IDisposable
 13    {
 14#pragma warning disable IDE1006 // Naming Styles
 15#pragma warning disable SX1309 // Field names should begin with underscore
 1016        private readonly byte[] privateKey = new byte[Ed25519.ExpandedPrivateKeySizeInBytes];
 17#pragma warning restore SX1309 // Field names should begin with underscore
 18#pragma warning restore IDE1006 // Naming Styles
 19        private ED25519DigitalSignature _digitalSignature;
 1020        private byte[] _publicKey = new byte[Ed25519.PublicKeySizeInBytes];
 21        private bool _isDisposed;
 22
 23        /// <summary>
 24        /// Gets the name of the key.
 25        /// </summary>
 26        /// <returns>
 27        /// The name of the key.
 28        /// </returns>
 29        public override string ToString()
 730        {
 731            return "ssh-ed25519";
 732        }
 33
 34        /// <summary>
 35        /// Gets or sets the public.
 36        /// </summary>
 37        /// <value>
 38        /// The public.
 39        /// </value>
 40        public override BigInteger[] Public
 41        {
 42            get
 443            {
 444                return new BigInteger[] { _publicKey.ToBigInteger2() };
 445            }
 46            set
 347            {
 348                _publicKey = value[0].ToByteArray().Reverse().TrimLeadingZeros().Pad(Ed25519.PublicKeySizeInBytes);
 349            }
 50        }
 51
 52        /// <summary>
 53        /// Gets the length of the key.
 54        /// </summary>
 55        /// <value>
 56        /// The length of the key.
 57        /// </value>
 58        public override int KeyLength
 59        {
 60            get
 361            {
 362                return PublicKey.Length * 8;
 363            }
 64        }
 65
 66        /// <summary>
 67        /// Gets the digital signature.
 68        /// </summary>
 69        protected internal override DigitalSignature DigitalSignature
 70        {
 71            get
 1072            {
 1073                _digitalSignature ??= new ED25519DigitalSignature(this);
 1074                return _digitalSignature;
 1075            }
 76        }
 77
 78        /// <summary>
 79        /// Gets the PublicKey Bytes.
 80        /// </summary>
 81        public byte[] PublicKey
 82        {
 83            get
 684            {
 685                return _publicKey;
 686            }
 87        }
 88
 89        /// <summary>
 90        /// Gets the PrivateKey Bytes.
 91        /// </summary>
 92        public byte[] PrivateKey
 93        {
 94            get
 195            {
 196                return privateKey;
 197            }
 98        }
 99
 100        /// <summary>
 101        /// Initializes a new instance of the <see cref="ED25519Key"/> class.
 102        /// </summary>
 3103        public ED25519Key()
 3104        {
 3105        }
 106
 107        /// <summary>
 108        /// Initializes a new instance of the <see cref="ED25519Key"/> class.
 109        /// </summary>
 110        /// <param name="pk">pk data.</param>
 0111        public ED25519Key(byte[] pk)
 0112        {
 0113            _publicKey = pk.TrimLeadingZeros().Pad(Ed25519.PublicKeySizeInBytes);
 0114        }
 115
 116        /// <summary>
 117        /// Initializes a new instance of the <see cref="ED25519Key"/> class.
 118        /// </summary>
 119        /// <param name="pk">pk data.</param>
 120        /// <param name="sk">sk data.</param>
 7121        public ED25519Key(byte[] pk, byte[] sk)
 7122        {
 7123            _publicKey = pk.TrimLeadingZeros().Pad(Ed25519.PublicKeySizeInBytes);
 7124            var seed = new byte[Ed25519.PrivateKeySeedSizeInBytes];
 7125            Buffer.BlockCopy(sk, 0, seed, 0, seed.Length);
 7126            Ed25519.KeyPairFromSeed(out _publicKey, out privateKey, seed);
 7127        }
 128
 129        /// <summary>
 130        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 131        /// </summary>
 132        public void Dispose()
 0133        {
 0134            Dispose(disposing: true);
 0135            GC.SuppressFinalize(this);
 0136        }
 137
 138        /// <summary>
 139        /// Releases unmanaged and - optionally - managed resources.
 140        /// </summary>
 141        /// <param name="disposing"><see langword="true"/> to release both managed and unmanaged resources; <see langwor
 142        protected virtual void Dispose(bool disposing)
 10143        {
 10144            if (_isDisposed)
 0145            {
 0146                return;
 147            }
 148
 10149            if (disposing)
 0150            {
 0151                _isDisposed = true;
 0152            }
 10153        }
 154
 155        /// <summary>
 156        /// Finalizes an instance of the <see cref="ED25519Key"/> class.
 157        /// </summary>
 158        ~ED25519Key()
 20159        {
 10160            Dispose(disposing: false);
 20161        }
 162    }
 163}