// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell http://www.novell.com
+// Copyright (C) 2004, 2007-2008 Novell, Inc (http://www.novell.com)
//
using NUnit.Framework;
public class SHA512Test : HashAlgorithmTest {
[SetUp]
- protected override void SetUp ()
+ public override void SetUp ()
{
hash = SHA512.Create ();
}
+ // the hash algorithm only exists as a managed implementation
+ public override bool ManagedHashImplementation {
+ get { return true; }
+ }
+
// test vectors from NIST FIPS 186-2
private string input1 = "abc";
public void FIPS186_a (string testName, SHA512 hash, byte[] input, byte[] result)
{
byte[] output = hash.ComputeHash (input);
- AssertEquals (testName + ".a.1", result, output);
- AssertEquals (testName + ".a.2", result, hash.Hash);
+ Assert.AreEqual (result, output, testName + ".a.1");
+ Assert.AreEqual (result, hash.Hash, testName + ".a.2");
// required or next operation will still return old hash
hash.Initialize ();
}
public void FIPS186_b (string testName, SHA512 hash, byte[] input, byte[] result)
{
byte[] output = hash.ComputeHash (input, 0, input.Length);
- AssertEquals (testName + ".b.1", result, output);
- AssertEquals (testName + ".b.2", result, hash.Hash);
+ Assert.AreEqual (result, output, testName + ".b.1");
+ Assert.AreEqual (result, hash.Hash, testName + ".b.2");
// required or next operation will still return old hash
hash.Initialize ();
}
{
MemoryStream ms = new MemoryStream (input);
byte[] output = hash.ComputeHash (ms);
- AssertEquals (testName + ".c.1", result, output);
- AssertEquals (testName + ".c.2", result, hash.Hash);
+ Assert.AreEqual (result, output, testName + ".c.1");
+ Assert.AreEqual (result, hash.Hash, testName + ".c.2");
// required or next operation will still return old hash
hash.Initialize ();
}
byte[] output = hash.TransformFinalBlock (input, 0, input.Length);
// LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
// AssertEquals( testName + ".d.1", result, output );
- AssertEquals (testName + ".d", result, hash.Hash);
+ Assert.IsNotNull (output, testName + ".d.1");
+ Assert.AreEqual (result, hash.Hash, testName + ".d.2");
// required or next operation will still return old hash
hash.Initialize ();
}
byte[] output = hash.TransformFinalBlock (input, input.Length - 1, 1);
// LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
// AssertEquals (testName + ".e.1", result, output);
- AssertEquals (testName + ".e", result, hash.Hash);
+ Assert.IsNotNull (output, testName + ".e.1");
+ Assert.AreEqual (result, hash.Hash, testName + ".e.2");
// required or next operation will still return old hash
hash.Initialize ();
}
// try to build the default implementation
SHA512 hash = SHA512.Create ();
- AssertEquals ("SHA512.Create()", hash.ToString (), defaultSHA512);
+ Assert.AreEqual (hash.ToString (), defaultSHA512, "SHA512.Create()");
// try to build, in every way, a SHA512 implementation
hash = SHA512.Create ("SHA512");
- AssertEquals ("SHA512.Create('SHA512')", hash.ToString (), defaultSHA512);
+ Assert.AreEqual (hash.ToString (), defaultSHA512, "SHA512.Create('SHA512')");
hash = SHA512.Create ("SHA-512");
- AssertEquals ("SHA512.Create('SHA-512')", hash.ToString (), defaultSHA512);
+ Assert.AreEqual (hash.ToString (), defaultSHA512, "SHA512.Create('SHA-512')");
}
[Test]
{
// try to build invalid implementation
hash = SHA512.Create ("InvalidHash");
- AssertNull ("SHA512.Create('InvalidHash')", hash);
+ Assert.IsNull (hash, "SHA512.Create('InvalidHash')");
}
[Test]
public virtual void StaticInfo ()
{
string className = hash.ToString ();
- AssertEquals (className + ".HashSize", 512, hash.HashSize);
- AssertEquals (className + ".InputBlockSize", 1, hash.InputBlockSize);
- AssertEquals (className + ".OutputBlockSize", 1, hash.OutputBlockSize);
+ Assert.AreEqual (512, hash.HashSize, className + ".HashSize");
+ Assert.AreEqual (1, hash.InputBlockSize, className + ".InputBlockSize");
+ Assert.AreEqual (1, hash.OutputBlockSize, className + ".OutputBlockSize");
}
}