Merge pull request #225 from mistoll/master
[mono.git] / mcs / class / corlib / Test / System.Security.Cryptography / TripleDESCryptoServiceProviderTest.cs
index 4c43000496d42a3df6900f76d8740a8a211d00b1..7f3190c62d8c166208aa4f20682c460a0022fcc0 100644 (file)
@@ -60,6 +60,12 @@ namespace MonoTests.System.Security.Cryptography {
                        ICryptoTransform decryptor = tdes.CreateDecryptor (tdes.Key, tdes.IV);
                        byte[] decdata = decryptor.TransformFinalBlock (encdata, 0, encdata.Length);
                        // null key != SymmetricAlgorithm.Key
+
+                       // in about 1 out of 256 runs the exception will not be thrown because the padding will be
+                       // the same as expected - however this still won't produce the right results (next check)
+                       Assert.IsFalse (BitConverter.ToString (data) == BitConverter.ToString (decdata), "Compare");
+                       // so this case is ok too, throw the expected exception to make the unit test succeed
+                       throw new CryptographicException ("1/256");
                }
 
                [Test]
@@ -108,6 +114,12 @@ namespace MonoTests.System.Security.Cryptography {
                        ICryptoTransform decryptor = tdes.CreateDecryptor (null, tdes.IV);
                        byte[] decdata = decryptor.TransformFinalBlock (encdata, 0, encdata.Length);
                        // null key != SymmetricAlgorithm.Key
+
+                       // in about 1 out of 256 runs the exception will not be thrown because the padding will be
+                       // the same as expected - however this still won't produce the right results (next check)
+                       Assert.IsFalse (BitConverter.ToString (data) == BitConverter.ToString (decdata), "Compare");
+                       // so this case is ok too, throw the expected exception to make the unit test succeed
+                       throw new CryptographicException ("1/256");
                }
 
                [Test]