Throw on invalid enum value in the ctor.
public CryptoStream (Stream stream, ICryptoTransform transform, CryptoStreamMode mode)
{
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;
}
_stream = stream;
_transform = transform;
[Test]
public void ImplicitFlushCascade ()
{
[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);
MyStream ms = new MyStream ();
ms.FlushCounterEnabled = true;
CryptoStream cs1 = new CryptoStream (ms, SHA1.Create (), CryptoStreamMode.Read);
Assert.IsTrue (ms.FlushCounter == 1);
}
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;}
class MyCryptoStream : CryptoStream {
public bool DisposeCalled { get; private set;}