[CryptoStream] Invalid enum in ctor
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 8 Oct 2010 00:59:29 +0000 (20:59 -0400)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 8 Oct 2010 19:31:43 +0000 (15:31 -0400)
Throw on invalid enum value in the ctor.

mcs/class/corlib/System.Security.Cryptography/CryptoStream.cs
mcs/class/corlib/Test/System.Security.Cryptography/CryptoStreamTest.cs

index ae9da714d698f9ffd1a81a1555d458a9e340bb0d..3c4890d610590c55ce5a801aee695e5135361b83 100644 (file)
@@ -57,13 +57,14 @@ namespace System.Security.Cryptography {
                
                public CryptoStream (Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
                {
-                       if ((mode == CryptoStreamMode.Read) && (!stream.CanRead)) {
-                               throw new ArgumentException (
-                                       Locale.GetText ("Can't read on stream"));
-                       }
-                       if ((mode == CryptoStreamMode.Write) && (!stream.CanWrite)) {
-                               throw new ArgumentException (
-                                       Locale.GetText ("Can't write on stream"));
+                       if (mode == CryptoStreamMode.Read) {
+                               if (!stream.CanRead)
+                                       throw new ArgumentException (Locale.GetText ("Can't read on stream"));
+                       } else if (mode == CryptoStreamMode.Write) {
+                               if (!stream.CanWrite)
+                                       throw new ArgumentException (Locale.GetText ("Can't write on stream"));
+                       } else {
+                               throw new ArgumentException ("mode");
                        }
                        _stream = stream;
                        _transform = transform;
index 5b959d13b6317fda8f063e07b7bdffdb717cc931..8d306d3e6e2c09f76aa7adfe9a49231bf5238b75 100644 (file)
@@ -1441,7 +1441,7 @@ namespace MonoTests.System.Security.Cryptography {
                [Test]
                public void ImplicitFlushCascade ()
                {
-                       // Tests that Dispose() calls Flush on the underlying stream
+                       // Tests that Dispose() calls FlushFinalBlock() on the underlying stream
                        MyStream ms = new MyStream ();
                        ms.FlushCounterEnabled = true;
                        CryptoStream cs1 = new CryptoStream (ms, SHA1.Create (), CryptoStreamMode.Read);
@@ -1450,6 +1450,13 @@ namespace MonoTests.System.Security.Cryptography {
                        Assert.IsTrue (ms.FlushCounter == 1);
                }
 
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void Ctor_InvalidEnumValue ()
+               {
+                       CryptoStream cs = new CryptoStream (Stream.Null, SHA1.Create (), (CryptoStreamMode) 0xff);
+               }
+
                class MyCryptoStream : CryptoStream {
                        public bool DisposeCalled { get; private set;}