New test.
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / HMACSHA1Test.cs
index 1d4d19465f9d858df20a319e9b3bd3bb1db4f9c0..c52e203c3cdd6dd186698f77a6a7008b5ade4fae 100644 (file)
@@ -5,7 +5,7 @@
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004, 2006 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
@@ -45,6 +45,13 @@ public class HMACSHA1Test : KeyedHashAlgorithmTest {
 
        protected HMACSHA1 algo;
 
+       [SetUp]
+       protected override void SetUp () 
+       {
+               hash = HMACSHA1.Create ();
+               (hash as KeyedHashAlgorithm).Key = new byte [8];
+       }
+
        [Test]
        public void Constructors () 
        {
@@ -80,13 +87,12 @@ public class HMACSHA1Test : KeyedHashAlgorithmTest {
        // this is legal in .NET 2.0 because HMACSHA1 derives from HMAC
        [Test]
        [ExpectedException (typeof (InvalidCastException))]
-       public void Exceptions () 
+       public void InvalidHashName () 
        {
                algo = new HMACSHA1 ();
                algo.HashName = "MD5";
                byte[] data = Encoding.Default.GetBytes ("MD5");
-               byte[] hmac = hash.ComputeHash (data);
-               Fail ("Expected InvalidCastException but got none");
+               byte[] hmac = algo.ComputeHash (data);
        }
 #endif
 
@@ -102,7 +108,11 @@ public class HMACSHA1Test : KeyedHashAlgorithmTest {
 
        public void CheckA (string testName, byte[] key, byte[] data, byte[] result) 
        {
+#if NET_2_0
+               algo = new HMACSHA1 (key, true);
+#else
                algo = new HMACSHA1 (key);
+#endif
                byte[] hmac = algo.ComputeHash (data);
                AssertEquals (testName + "a1", result, hmac);
                AssertEquals (testName + "a2", result, algo.Hash);
@@ -110,7 +120,11 @@ public class HMACSHA1Test : KeyedHashAlgorithmTest {
 
        public void CheckB (string testName, byte[] key, byte[] data, byte[] result) 
        {
+#if NET_2_0
+               algo = new HMACSHA1 (key, false);
+#else
                algo = new HMACSHA1 (key);
+#endif
                byte[] hmac = algo.ComputeHash (data, 0, data.Length);
                AssertEquals (testName + "b1", result, hmac);
                AssertEquals (testName + "b2", result, algo.Hash);