using System;
using Renci.SshNet.Common;
using Renci.SshNet.Security.Chaos.NaCl;
namespace Renci.SshNet.Security.Cryptography
{
    /// 
    /// Implements ECDSA digital signature algorithm.
    /// 
    public class ED25519DigitalSignature : DigitalSignature, IDisposable
    {
        private readonly ED25519Key _key;
        private bool _isDisposed;
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// The ED25519Key key.
        ///  is .
        public ED25519DigitalSignature(ED25519Key key)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            _key = key;
        }
        /// 
        /// Verifies the signature.
        /// 
        /// The input.
        /// The signature.
        /// 
        ///  if signature was successfully verified; otherwise .
        /// 
        /// Invalid signature.
        public override bool Verify(byte[] input, byte[] signature)
        {
            return Ed25519.Verify(signature, input, _key.PublicKey);
        }
        /// 
        /// Creates the signature.
        /// 
        /// The input.
        /// 
        /// Signed input data.
        /// 
        /// Invalid ED25519Key key.
        public override byte[] Sign(byte[] input)
        {
            return Ed25519.Sign(input, _key.PrivateKey);
        }
        /// 
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// 
        public void Dispose()
        {
            Dispose(disposing: true);
            GC.SuppressFinalize(this);
        }
        /// 
        /// Releases unmanaged and - optionally - managed resources.
        /// 
        ///  to release both managed and unmanaged resources;  to release only unmanaged resources.
        protected virtual void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }
            if (disposing)
            {
                _isDisposed = true;
            }
        }
        /// 
        /// Finalizes an instance of the  class.
        /// 
        ~ED25519DigitalSignature()
        {
            Dispose(disposing: false);
        }
    }
}