X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem.Security.Cryptography%2FHMACRIPEMD160Test.cs;h=7a99bfdc3207120972131fdbac73e080d56d86e5;hb=8f59998c4f744c7b78cf6cdd7f5849f99902c4b8;hp=1c39730625443663c238c660f1ccd3f98d4d2618;hpb=da4f9e9b2afb23791029d0bb09d78b868aabd870;p=mono.git diff --git a/mcs/class/corlib/Test/System.Security.Cryptography/HMACRIPEMD160Test.cs b/mcs/class/corlib/Test/System.Security.Cryptography/HMACRIPEMD160Test.cs index 1c397306254..7a99bfdc320 100644 --- a/mcs/class/corlib/Test/System.Security.Cryptography/HMACRIPEMD160Test.cs +++ b/mcs/class/corlib/Test/System.Security.Cryptography/HMACRIPEMD160Test.cs @@ -6,7 +6,7 @@ // Sebastien Pouliot (sebastien@ximian.com) // // (C) 2003 Motus Technologies Inc. (http://www.motus.com) -// Copyright (C) 2004, 2006 Novell, Inc (http://www.novell.com) +// Copyright (C) 2004, 2006, 2007 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -38,45 +38,32 @@ using System.Text; namespace MonoTests.System.Security.Cryptography { + public class HR160 : HMACRIPEMD160 { + + public int BlockSize { + get { return base.BlockSizeValue; } + set { base.BlockSizeValue = value; } + } + } + [TestFixture] public class HMACRIPEMD160Test : KeyedHashAlgorithmTest { protected HMACRIPEMD160 hmac; - // because most crypto stuff works with byte[] buffers - static public void AssertEquals (string msg, byte[] array1, byte[] array2) - { - if ((array1 == null) && (array2 == null)) - return; - if (array1 == null) - Fail (msg + " -> First array is NULL"); - if (array2 == null) - Fail (msg + " -> Second array is NULL"); - - bool a = (array1.Length == array2.Length); - if (a) { - for (int i = 0; i < array1.Length; i++) { - if (array1 [i] != array2 [i]) { - a = false; - break; - } - } - } - if (array1.Length > 0) { - msg += " -> Expected " + BitConverter.ToString (array1, 0); - msg += " is different than " + BitConverter.ToString (array2, 0); - } - Assert (msg, a); - } - [SetUp] - protected override void SetUp () + public override void SetUp () { hmac = new HMACRIPEMD160 (); hmac.Key = new byte [8]; hash = hmac; } + // the hash algorithm only exists as a managed implementation + public override bool ManagedHashImplementation { + get { return true; } + } + static byte[] key1 = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01, 0x23, 0x45, 0x67 }; // HMACRIPEMD160 (key1, "") = cf387677bfda8483e63b57e06c3b5ecd8b7fc055 @@ -382,8 +369,8 @@ namespace MonoTests.System.Security.Cryptography { public void HMACRIPEMD160_a (string testName, HMACRIPEMD160 hmac, byte[] input, byte[] result) { byte[] output = hmac.ComputeHash (input); - AssertEquals (testName + ".a.1", result, output); - AssertEquals (testName + ".a.2", result, hmac.Hash); + Assert.AreEqual (result, output, testName + ".a.1"); + Assert.AreEqual (result, hmac.Hash, testName + ".a.2"); // required or next operation will still return old hash hmac.Initialize (); } @@ -391,8 +378,8 @@ namespace MonoTests.System.Security.Cryptography { public void HMACRIPEMD160_b (string testName, HMACRIPEMD160 hmac, byte[] input, byte[] result) { byte[] output = hmac.ComputeHash (input, 0, input.Length); - AssertEquals (testName + ".b.1", result, output); - AssertEquals (testName + ".b.2", result, hmac.Hash); + Assert.AreEqual (result, output, testName + ".b.1"); + Assert.AreEqual (result, hmac.Hash, testName + ".b.2"); // required or next operation will still return old hash hmac.Initialize (); } @@ -401,8 +388,8 @@ namespace MonoTests.System.Security.Cryptography { { MemoryStream ms = new MemoryStream (input); byte[] output = hmac.ComputeHash (ms); - AssertEquals (testName + ".c.1", result, output); - AssertEquals (testName + ".c.2", result, hmac.Hash); + Assert.AreEqual (result, output, testName + ".c.1"); + Assert.AreEqual (result, hmac.Hash, testName + ".c.2"); // required or next operation will still return old hash hmac.Initialize (); } @@ -410,7 +397,7 @@ namespace MonoTests.System.Security.Cryptography { public void HMACRIPEMD160_d (string testName, HMACRIPEMD160 hmac, byte[] input, byte[] result) { hmac.TransformFinalBlock (input, 0, input.Length); - AssertEquals (testName + ".d", result, hmac.Hash); + Assert.AreEqual (result, hmac.Hash, testName + ".d"); // required or next operation will still return old hash hmac.Initialize (); } @@ -421,19 +408,29 @@ namespace MonoTests.System.Security.Cryptography { for (int i=0; i < input.Length - 1; i++) hmac.TransformBlock (input, i, 1, copy, i); hmac.TransformFinalBlock (input, input.Length - 1, 1); - AssertEquals (testName + ".e", result, hmac.Hash); + Assert.AreEqual (result, hmac.Hash, testName + ".e"); // required or next operation will still return old hash hmac.Initialize (); } // none of those values changes for any implementation of RIPEMD160 [Test] - public virtual void StaticInfo () + public void Invariants () + { + Assert.IsTrue (hmac.CanReuseTransform, "HMACRIPEMD160.CanReuseTransform"); + Assert.IsTrue (hmac.CanTransformMultipleBlocks, "HMACRIPEMD160.CanTransformMultipleBlocks"); + Assert.AreEqual ("RIPEMD160", hmac.HashName, "HMACRIPEMD160.HashName"); + Assert.AreEqual (160, hmac.HashSize, "HMACRIPEMD160.HashSize"); + Assert.AreEqual (1, hmac.InputBlockSize, "HMACRIPEMD160.InputBlockSize"); + Assert.AreEqual (1, hmac.OutputBlockSize, "HMACRIPEMD160.OutputBlockSize"); + Assert.AreEqual ("System.Security.Cryptography.HMACRIPEMD160", hmac.ToString (), "HMACRIPEMD160.ToString()"); + } + + [Test] + public void BlockSize () { - string className = hmac.ToString (); - AssertEquals (className + ".HashSize", 160, hmac.HashSize); - AssertEquals (className + ".InputBlockSize", 1, hmac.InputBlockSize); - AssertEquals (className + ".OutputBlockSize", 1, hmac.OutputBlockSize); + HR160 hmac = new HR160 (); + Assert.AreEqual (64, hmac.BlockSize, "BlockSizeValue"); } } }