dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/tests/runtime/System/Security/Cryptog


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/tests/runtime/System/Security/Cryptography CryptoTestCase.cs,1.2,1.3 TestMD5.cs,1.1,1.2 TestSHA1.cs,1.1,1.2 TestSHA256.cs,1.1,1.2 TestSHA384.cs,1.1,1.2 TestSHA512.cs,1.1,1.2
Date: Tue, 26 Nov 2002 06:52:03 -0500

Update of 
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Security/Cryptography
In directory 
subversions:/tmp/cvs-serv29265/tests/runtime/System/Security/Cryptography

Modified Files:
        CryptoTestCase.cs TestMD5.cs TestSHA1.cs TestSHA256.cs 
        TestSHA384.cs TestSHA512.cs 
Log Message:


Test hash algorithm properties and all forms of "ComputeHash".


Index: CryptoTestCase.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Security/Cryptography/CryptoTestCase.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** CryptoTestCase.cs   25 Nov 2002 23:14:17 -0000      1.2
--- CryptoTestCase.cs   26 Nov 2002 11:52:00 -0000      1.3
***************
*** 22,25 ****
--- 22,26 ----
  using System;
  using System.Reflection;
+ using System.IO;
  using System.Text;
  using System.Security.Cryptography;
***************
*** 168,171 ****
--- 169,204 ----
                                        Fail("incorrect hash value produced");
                                }
+ 
+                               // Get the hash value over the input in a 
sub-buffer.
+                               byte[] input2 = new byte [input.Length + 20];
+                               if(input.Length != 0)
+                               {
+                                       Array.Copy(input, 0, input2, 10, 
input.Length);
+                               }
+                               hash = alg.ComputeHash(input2, 10, 
input.Length);
+ 
+                               // Compare the hash with the expected value.
+                               AssertNotNull("returned hash was null", hash);
+                               AssertEquals("hash length is wrong", 
hash.Length,
+                                                        expected.Length);
+                               if(!IdenticalBlock(hash, 0, expected, 0, 
expected.Length))
+                               {
+                                       Fail("incorrect hash value produced");
+                               }
+ 
+ #if false // TODO
+                               // Get the hash value over the input via a 
stream.
+                               MemoryStream stream = new MemoryStream(input, 
false);
+                               hash = alg.ComputeHash(stream);
+ 
+                               // Compare the hash with the expected value.
+                               AssertNotNull("returned hash was null", hash);
+                               AssertEquals("hash length is wrong", 
hash.Length,
+                                                        expected.Length);
+                               if(!IdenticalBlock(hash, 0, expected, 0, 
expected.Length))
+                               {
+                                       Fail("incorrect hash value produced");
+                               }
+ #endif
                        }
        protected void RunHash(String name, String value, byte[] expected)
***************
*** 245,251 ****
                                                  alg.LegalBlockSizes, 
alg.BlockSize);
  
!                               // Try setting the key size to all legal values.
  
                                // TODO: check automatic key and IV generation
                        }
  
--- 278,306 ----
                                                  alg.LegalBlockSizes, 
alg.BlockSize);
  
!                               // TODO: Try setting the key size to all legal 
values.
  
                                // TODO: check automatic key and IV generation
+                       }
+ 
+       // Test the properties on a hash algorithm instance.
+       protected void HashPropertyTest(HashAlgorithm alg, int expectedHashSize)
+                       {
+                               AssertEquals("hash size is incorrect",
+                                                        alg.HashSize, 
expectedHashSize);
+                               AssertEquals("input block size is incorrect",
+                                                        alg.InputBlockSize, 1);
+                               AssertEquals("output block size is incorrect",
+                                                        alg.OutputBlockSize, 
1);
+                               AssertEquals("multiple block transform flag is 
incorrect",
+                                                        
alg.CanTransformMultipleBlocks, true);
+                               try
+                               {
+                                       byte[] hash = alg.Hash;
+                                       Fail("should not be able to get the 
hash yet");
+                               }
+                               catch(CryptographicException)
+                               {
+                                       // Success
+                               }
                        }
  

Index: TestMD5.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Security/Cryptography/TestMD5.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** TestMD5.cs  22 Nov 2002 00:17:48 -0000      1.1
--- TestMD5.cs  26 Nov 2002 11:52:00 -0000      1.2
***************
*** 143,145 ****
--- 143,151 ----
                        }
  
+       // Test the properties of the default algorithm instance.
+       public void TestMD5Properties()
+                       {
+                               HashPropertyTest(MD5.Create(), 128);
+                       }
+ 
  }; // TestMD5

Index: TestSHA1.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Security/Cryptography/TestSHA1.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** TestSHA1.cs 22 Nov 2002 00:17:48 -0000      1.1
--- TestSHA1.cs 26 Nov 2002 11:52:00 -0000      1.2
***************
*** 87,89 ****
--- 87,95 ----
                        }
  
+       // Test the properties of the default algorithm instance.
+       public void TestSHA1Properties()
+                       {
+                               HashPropertyTest(SHA1.Create(), 160);
+                       }
+ 
  }; // TestSHA1

Index: TestSHA256.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Security/Cryptography/TestSHA256.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** TestSHA256.cs       22 Nov 2002 00:17:48 -0000      1.1
--- TestSHA256.cs       26 Nov 2002 11:52:00 -0000      1.2
***************
*** 91,93 ****
--- 91,99 ----
                        }
  
+       // Test the properties of the default algorithm instance.
+       public void TestSHA256Properties()
+                       {
+                               HashPropertyTest(SHA256.Create(), 256);
+                       }
+ 
  }; // TestSHA256

Index: TestSHA384.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Security/Cryptography/TestSHA384.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** TestSHA384.cs       22 Nov 2002 00:17:48 -0000      1.1
--- TestSHA384.cs       26 Nov 2002 11:52:00 -0000      1.2
***************
*** 96,98 ****
--- 96,104 ----
                        }
  
+       // Test the properties of the default algorithm instance.
+       public void TestSHA384Properties()
+                       {
+                               HashPropertyTest(SHA384.Create(), 384);
+                       }
+ 
  }; // TestSHA384

Index: TestSHA512.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Security/Cryptography/TestSHA512.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** TestSHA512.cs       22 Nov 2002 00:17:48 -0000      1.1
--- TestSHA512.cs       26 Nov 2002 11:52:00 -0000      1.2
***************
*** 100,102 ****
--- 100,108 ----
                        }
  
+       // Test the properties of the default algorithm instance.
+       public void TestSHA512Properties()
+                       {
+                               HashPropertyTest(SHA512.Create(), 512);
+                       }
+ 
  }; // TestSHA512





reply via email to

[Prev in Thread] Current Thread [Next in Thread]