X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=Novacoin%2FHash.cs;h=5386cb3fa0db4c2623fee9dc281b9c55584f4ca4;hb=2bb857d97dc61c7b9230b3db919f048bbeb9c76a;hp=92ce2c75c9af82ff99244f0303c10ea713f89657;hpb=5671ee17bc35fb578e18168833c5d1e3e86a7e28;p=NovacoinLibrary.git diff --git a/Novacoin/Hash.cs b/Novacoin/Hash.cs index 92ce2c7..5386cb3 100644 --- a/Novacoin/Hash.cs +++ b/Novacoin/Hash.cs @@ -82,17 +82,14 @@ namespace Novacoin public bool Equals(Hash item) { - if (item == null) - { - return false; - } - + Contract.Requires((object)item != null, "Null reference is not allowed."); return _hashBytes.SequenceEqual((byte[])item); } public override bool Equals(object o) { - throw new NotSupportedException(); + Contract.Requires(o != null, "Null reference is not allowed."); + return _hashBytes.SequenceEqual(((Hash)o)._hashBytes); } public override int GetHashCode() @@ -102,8 +99,8 @@ namespace Novacoin public int CompareTo(Hash item) { + Contract.Requires((object)item != null, "Null reference is not allowed."); Contract.Requires(item.hashSize == hashSize, "Hashes must have the same size."); - Contract.Requires(item != null, "Null reference is not allowed."); if (this > item) { @@ -119,6 +116,7 @@ namespace Novacoin public static bool operator <(Hash a, Hash b) { + Contract.Requires((object)a != null && (object)b != null, "Null references are not allowed."); Contract.Requires(a.hashSize == b.hashSize, "Hashes must have the same size."); for (int i = a.hashSize - 1; i >= 0; i--) @@ -134,6 +132,7 @@ namespace Novacoin public static bool operator <=(Hash a, Hash b) { + Contract.Requires((object)a != null && (object)b != null, "Null references are not allowed."); Contract.Requires(a.hashSize == b.hashSize, "Hashes must have the same size."); for (int i = a.hashSize - 1; i >= 0; i--) @@ -149,6 +148,7 @@ namespace Novacoin public static bool operator >(Hash a, Hash b) { + Contract.Requires((object)a != null && (object)b != null, "Null references are not allowed."); Contract.Requires(a.hashSize == b.hashSize, "Hashes must have the same size."); for (int i = a.hashSize - 1; i >= 0; i--) @@ -164,6 +164,7 @@ namespace Novacoin public static bool operator >=(Hash a, Hash b) { + Contract.Requires((object)a != null && (object)b != null, "Null references are not allowed."); Contract.Requires(a.hashSize == b.hashSize, "Hashes must have the same size."); for (int i = a.hashSize - 1; i >= 0; i--) @@ -179,6 +180,7 @@ namespace Novacoin public static bool operator ==(Hash a, Hash b) { + Contract.Requires((object)a != null && (object)b != null, "Null references are not allowed."); Contract.Requires(a.hashSize == b.hashSize, "Hashes must have the same size."); return a._hashBytes.SequenceEqual(b._hashBytes); @@ -186,9 +188,10 @@ namespace Novacoin public static bool operator !=(Hash a, Hash b) { + Contract.Requires((object)a != null && (object)b != null, "Null references are not allowed."); Contract.Requires(a.hashSize == b.hashSize, "Hashes must have the same size."); - return !a._hashBytes.SequenceEqual(b._hashBytes); + return !a.Equals(b); } public override string ToString()