summary refs log tree commit diff
path: root/crypto/src/util
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-11-04 19:28:43 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-11-04 19:28:43 +0700
commitf56fc16973d66bd9461f247e50738e55bd54de7e (patch)
tree8e84c9bd2cfc2d554b99c8045ec46de7313410fc /crypto/src/util
parentPort updated revocation test from Java (diff)
downloadBouncyCastle.NET-ed25519-f56fc16973d66bd9461f247e50738e55bd54de7e.tar.xz
Replace Close with Dispose for PORTABLE
Diffstat (limited to 'crypto/src/util')
-rw-r--r--crypto/src/util/io/BaseInputStream.cs20
-rw-r--r--crypto/src/util/io/BaseOutputStream.cs20
-rw-r--r--crypto/src/util/io/FilterStream.cs11
-rw-r--r--crypto/src/util/io/TeeInputStream.cs14
-rw-r--r--crypto/src/util/io/TeeOutputStream.cs14
-rw-r--r--crypto/src/util/zlib/ZDeflaterOutputStream.cs19
-rw-r--r--crypto/src/util/zlib/ZInflaterInputStream.cs16
-rw-r--r--crypto/src/util/zlib/ZInputStream.cs17
-rw-r--r--crypto/src/util/zlib/ZOutputStream.cs57
9 files changed, 160 insertions, 28 deletions
diff --git a/crypto/src/util/io/BaseInputStream.cs b/crypto/src/util/io/BaseInputStream.cs
index 3ff4a1957..36725acd2 100644
--- a/crypto/src/util/io/BaseInputStream.cs
+++ b/crypto/src/util/io/BaseInputStream.cs
@@ -11,8 +11,24 @@ namespace Org.BouncyCastle.Utilities.IO
 		public sealed override bool CanRead { get { return !closed; } }
         public sealed override bool CanSeek { get { return false; } }
         public sealed override bool CanWrite { get { return false; } }
-		public override void Close() { closed = true; }
-		public sealed override void Flush() {}
+
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+                closed = true;
+            }
+            base.Dispose(disposing);
+        }
+#else
+		public override void Close()
+        {
+            closed = true;
+        }
+#endif
+
+        public sealed override void Flush() {}
         public sealed override long Length { get { throw new NotSupportedException(); } }
         public sealed override long Position
         {
diff --git a/crypto/src/util/io/BaseOutputStream.cs b/crypto/src/util/io/BaseOutputStream.cs
index 6e6c6d346..d85ae8ae4 100644
--- a/crypto/src/util/io/BaseOutputStream.cs
+++ b/crypto/src/util/io/BaseOutputStream.cs
@@ -11,8 +11,24 @@ namespace Org.BouncyCastle.Utilities.IO
 		public sealed override bool CanRead { get { return false; } }
         public sealed override bool CanSeek { get { return false; } }
         public sealed override bool CanWrite { get { return !closed; } }
-		public override void Close() { closed = true; }
-        public override void Flush() {}
+
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+                closed = true;
+            }
+            base.Dispose(disposing);
+        }
+#else
+        public override void Close()
+        {
+            closed = true;
+        }
+#endif
+
+        public override void Flush() { }
         public sealed override long Length { get { throw new NotSupportedException(); } }
         public sealed override long Position
         {
diff --git a/crypto/src/util/io/FilterStream.cs b/crypto/src/util/io/FilterStream.cs
index c5d6a1cba..be216254a 100644
--- a/crypto/src/util/io/FilterStream.cs
+++ b/crypto/src/util/io/FilterStream.cs
@@ -29,10 +29,21 @@ namespace Org.BouncyCastle.Utilities.IO
             get { return s.Position; }
             set { s.Position = value; }
         }
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+                Platform.Dispose(s);
+            }
+            base.Dispose(disposing);
+        }
+#else
         public override void Close()
         {
             Platform.Dispose(s);
         }
+#endif
         public override void Flush()
         {
             s.Flush();
diff --git a/crypto/src/util/io/TeeInputStream.cs b/crypto/src/util/io/TeeInputStream.cs
index b344be8a8..4b3203d71 100644
--- a/crypto/src/util/io/TeeInputStream.cs
+++ b/crypto/src/util/io/TeeInputStream.cs
@@ -18,11 +18,23 @@ namespace Org.BouncyCastle.Utilities.IO
 			this.tee = tee;
 		}
 
-		public override void Close()
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+                Platform.Dispose(input);
+                Platform.Dispose(tee);
+            }
+            base.Dispose(disposing);
+        }
+#else
+        public override void Close()
 		{
             Platform.Dispose(input);
             Platform.Dispose(tee);
 		}
+#endif
 
         public override int Read(byte[] buf, int off, int len)
 		{
diff --git a/crypto/src/util/io/TeeOutputStream.cs b/crypto/src/util/io/TeeOutputStream.cs
index 75d1d305d..7ad14a007 100644
--- a/crypto/src/util/io/TeeOutputStream.cs
+++ b/crypto/src/util/io/TeeOutputStream.cs
@@ -18,11 +18,23 @@ namespace Org.BouncyCastle.Utilities.IO
 			this.tee = tee;
 		}
 
-		public override void Close()
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+                Platform.Dispose(output);
+                Platform.Dispose(tee);
+            }
+            base.Dispose(disposing);
+        }
+#else
+        public override void Close()
 		{
             Platform.Dispose(output);
             Platform.Dispose(tee);
 		}
+#endif
 
         public override void Write(byte[] buffer, int offset, int count)
 		{
diff --git a/crypto/src/util/zlib/ZDeflaterOutputStream.cs b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
index 7ff6d31c8..5a70df21d 100644
--- a/crypto/src/util/zlib/ZDeflaterOutputStream.cs
+++ b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
@@ -136,6 +136,24 @@ namespace Org.BouncyCastle.Utilities.Zlib {
             z=null;
         }
         
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+                try{
+                    try{Finish();}
+                    catch (IOException) {}
+                }
+                finally{
+                    End();
+                    Platform.Dispose(outp);
+                    outp=null;
+                }
+            }
+            base.Dispose(disposing);
+        }
+#else
         public override void Close() {
             try{
                 try{Finish();}
@@ -147,5 +165,6 @@ namespace Org.BouncyCastle.Utilities.Zlib {
                 outp=null;
             }
         }
+#endif
     }
 }
diff --git a/crypto/src/util/zlib/ZInflaterInputStream.cs b/crypto/src/util/zlib/ZInflaterInputStream.cs
index 170596e63..df51fc878 100644
--- a/crypto/src/util/zlib/ZInflaterInputStream.cs
+++ b/crypto/src/util/zlib/ZInflaterInputStream.cs
@@ -114,10 +114,22 @@ namespace Org.BouncyCastle.Utilities.Zlib {
         public override void WriteByte(byte b) {
         }
 
-        public override void Close() {
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+                Platform.Dispose(inp);
+            }
+            base.Dispose(disposing);
+        }
+#else
+        public override void Close()
+        {
             Platform.Dispose(inp);
         }
-    
+#endif
+
         public override int ReadByte() {
             if(Read(buf1, 0, 1)<=0)
                 return -1;
diff --git a/crypto/src/util/zlib/ZInputStream.cs b/crypto/src/util/zlib/ZInputStream.cs
index f0b3068fc..fe895a397 100644
--- a/crypto/src/util/zlib/ZInputStream.cs
+++ b/crypto/src/util/zlib/ZInputStream.cs
@@ -93,7 +93,21 @@ namespace Org.BouncyCastle.Utilities.Zlib
 		public sealed override bool CanSeek { get { return false; } }
 		public sealed override bool CanWrite { get { return false; } }
 
-		public override void Close()
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+			    if (!closed)
+			    {
+				    closed = true;
+                    Platform.Dispose(input);
+			    }
+            }
+            base.Dispose(disposing);
+        }
+#else
+        public override void Close()
 		{
 			if (!closed)
 			{
@@ -101,6 +115,7 @@ namespace Org.BouncyCastle.Utilities.Zlib
                 Platform.Dispose(input);
 			}
 		}
+#endif
 
 		public sealed override void Flush() {}
 
diff --git a/crypto/src/util/zlib/ZOutputStream.cs b/crypto/src/util/zlib/ZOutputStream.cs
index 7b49d6638..ca59d8e1f 100644
--- a/crypto/src/util/zlib/ZOutputStream.cs
+++ b/crypto/src/util/zlib/ZOutputStream.cs
@@ -95,32 +95,51 @@ namespace Org.BouncyCastle.Utilities.Zlib
         public sealed override bool CanSeek { get { return false; } }
         public sealed override bool CanWrite { get { return !closed; } }
 
+#if PORTABLE
+        protected override void Disposing(bool disposing)
+        {
+            if (disposing)
+            {
+			    if (this.closed)
+				    return;
+
+                DoClose();
+            }
+            base.Dispose(disposing);
+        }
+#else
 		public override void Close()
 		{
 			if (this.closed)
 				return;
 
-			try
-			{
-				try
-				{
-					Finish();
-				}
-				catch (IOException)
-				{
-					// Ignore
-				}
-			}
-			finally
-			{
-				this.closed = true;
-				End();
-                Platform.Dispose(output);
-				output = null;
-			}
+            DoClose();
 		}
+#endif
+
+        private void DoClose()
+        {
+            try
+            {
+                try
+                {
+                    Finish();
+                }
+                catch (IOException)
+                {
+                    // Ignore
+                }
+            }
+            finally
+            {
+                this.closed = true;
+                End();
+                Platform.Dispose(output);
+                output = null;
+            }
+        }
 
-		public virtual void End()
+        public virtual void End()
 		{
 			if (z == null)
 				return;