using System.Security.Cryptography;
using System.Collections.Generic;
using System.Linq;
namespace Novacoin
{
public abstract class Hash
{
///
/// Computes the SHA256 hash for the input data using the managed library.
///
protected static SHA256Managed _hasher256 = new SHA256Managed();
///
/// Array of digest bytes.
///
protected byte[] _hashBytes = null;
///
/// Hash size, must be overriden
///
public virtual int hashSize
{
get;
}
public byte[] hashBytes
{
get { return _hashBytes; }
}
///
/// Initializes an empty instance of the Hash class.
///
public Hash()
{
_hashBytes = Enumerable.Repeat(0, hashSize).ToArray();
}
///
/// Initializes a new instance of Hash class with first 20 bytes from supplied list
///
/// List of bytes
public Hash(IEnumerable bytes)
{
_hashBytes = bytes.Take(hashSize).ToArray();
}
public Hash(byte[] bytes)
{
_hashBytes = bytes;
}
public bool IsZero
{
get { return !_hashBytes.Any(b => b != 0); }
}
public override string ToString()
{
return Interop.ToHex(Interop.ReverseBytes(_hashBytes));
}
}
}