summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-11-04 16:11:28 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-11-04 16:11:28 +0700
commited2134bdcf763b2b6a11742911b4c5efd1de4550 (patch)
treeb23f6dfb1ee88ddc393276229c014204b42aea22
parentPerform counter increment without branches (diff)
downloadBouncyCastle.NET-ed25519-ed2134bdcf763b2b6a11742911b4c5efd1de4550.tar.xz
Change Close calls to Dispose calls for PORTABLE
-rw-r--r--crypto/bzip2/src/CBZip2InputStream.cs6
-rw-r--r--crypto/bzip2/src/CBZip2OutputStream.cs4
-rw-r--r--crypto/src/asn1/DerSequence.cs7
-rw-r--r--crypto/src/asn1/DerSet.cs7
-rw-r--r--crypto/src/asn1/util/Dump.cs4
-rw-r--r--crypto/src/asn1/util/FilterStream.cs4
-rw-r--r--crypto/src/bcpg/ArmoredInputStream.cs2
-rw-r--r--crypto/src/bcpg/BcpgInputStream.cs3
-rw-r--r--crypto/src/bcpg/BcpgOutputStream.cs3
-rw-r--r--crypto/src/bcpg/PublicKeyEncSessionPacket.cs2
-rw-r--r--crypto/src/cms/CMSAuthenticatedDataGenerator.cs6
-rw-r--r--crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs5
-rw-r--r--crypto/src/cms/CMSCompressedData.cs3
-rw-r--r--crypto/src/cms/CMSCompressedDataGenerator.cs5
-rw-r--r--crypto/src/cms/CMSCompressedDataStreamGenerator.cs7
-rw-r--r--crypto/src/cms/CMSContentInfoParser.cs3
-rw-r--r--crypto/src/cms/CMSEnvelopedDataGenerator.cs4
-rw-r--r--crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs4
-rw-r--r--crypto/src/cms/CMSProcessableFile.cs3
-rw-r--r--crypto/src/cms/CMSProcessableInputStream.cs3
-rw-r--r--crypto/src/cms/CMSSignedDataGenerator.cs2
-rw-r--r--crypto/src/cms/CMSSignedDataParser.cs8
-rw-r--r--crypto/src/cms/CMSSignedDataStreamGenerator.cs6
-rw-r--r--crypto/src/cms/CMSTypedStream.cs3
-rw-r--r--crypto/src/crypto/io/CipherStream.cs5
-rw-r--r--crypto/src/crypto/io/DigestStream.cs6
-rw-r--r--crypto/src/crypto/io/MacStream.cs6
-rw-r--r--crypto/src/crypto/io/SignerStream.cs6
-rw-r--r--crypto/src/crypto/parameters/SkeinParameters.cs2
-rw-r--r--crypto/src/crypto/tls/CertificateUrl.cs2
-rw-r--r--crypto/src/crypto/tls/DtlsReliableHandshake.cs2
-rw-r--r--crypto/src/crypto/tls/RecordStream.cs6
-rw-r--r--crypto/src/crypto/tls/TlsProtocol.cs2
-rw-r--r--crypto/src/ocsp/BasicOCSPRespGenerator.cs2
-rw-r--r--crypto/src/openpgp/PgpCompressedDataGenerator.cs3
-rw-r--r--crypto/src/openpgp/PgpUtilities.cs4
-rw-r--r--crypto/src/pkcs/Pkcs10CertificationRequest.cs4
-rw-r--r--crypto/src/pkix/PkixCertPath.cs2
-rw-r--r--crypto/src/util/Platform.cs18
-rw-r--r--crypto/src/util/io/FilterStream.cs2
-rw-r--r--crypto/src/util/io/TeeInputStream.cs6
-rw-r--r--crypto/src/util/io/TeeOutputStream.cs6
-rw-r--r--crypto/src/util/zlib/ZDeflaterOutputStream.cs2
-rw-r--r--crypto/src/util/zlib/ZInflaterInputStream.cs2
-rw-r--r--crypto/src/util/zlib/ZInputStream.cs2
-rw-r--r--crypto/src/util/zlib/ZOutputStream.cs2
-rw-r--r--crypto/src/x509/X509Certificate.cs2
-rw-r--r--crypto/src/x509/X509Crl.cs2
-rw-r--r--crypto/src/x509/X509V1CertificateGenerator.cs3
-rw-r--r--crypto/src/x509/X509V2AttributeCertificate.cs4
-rw-r--r--crypto/src/x509/X509V2AttributeCertificateGenerator.cs6
-rw-r--r--crypto/src/x509/X509V2CRLGenerator.cs5
52 files changed, 135 insertions, 83 deletions
diff --git a/crypto/bzip2/src/CBZip2InputStream.cs b/crypto/bzip2/src/CBZip2InputStream.cs
index 7efb3b3ab..82ff83e42 100644
--- a/crypto/bzip2/src/CBZip2InputStream.cs
+++ b/crypto/bzip2/src/CBZip2InputStream.cs
@@ -25,6 +25,8 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Apache.Bzip2
 {
 	/**
@@ -286,10 +288,10 @@ namespace Org.BouncyCastle.Apache.Bzip2
             Cadvise();
         }
 
-		private void BsFinishedWithStream() {
+        private void BsFinishedWithStream() {
             try {
                 if (this.bsStream != null) {
-                    this.bsStream.Close();
+                    Platform.Dispose(this.bsStream);
                     this.bsStream = null;
                 }
             } catch {
diff --git a/crypto/bzip2/src/CBZip2OutputStream.cs b/crypto/bzip2/src/CBZip2OutputStream.cs
index bf43a6a6c..73e6979d8 100644
--- a/crypto/bzip2/src/CBZip2OutputStream.cs
+++ b/crypto/bzip2/src/CBZip2OutputStream.cs
@@ -25,6 +25,8 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Apache.Bzip2
 {
 	/**
@@ -393,7 +395,7 @@ namespace Org.BouncyCastle.Apache.Bzip2
 
             closed = true;
             base.Close();
-            bsStream.Close();
+            Platform.Dispose(this.bsStream);
         }
 
         public void Finish() {
diff --git a/crypto/src/asn1/DerSequence.cs b/crypto/src/asn1/DerSequence.cs
index b50a77962..a76cf2882 100644
--- a/crypto/src/asn1/DerSequence.cs
+++ b/crypto/src/asn1/DerSequence.cs
@@ -1,6 +1,9 @@
+using System;
 using System.Collections;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Asn1
 {
 	public class DerSequence
@@ -75,9 +78,9 @@ namespace Org.BouncyCastle.Asn1
 				dOut.WriteObject(obj);
 			}
 
-			dOut.Close();
+            Platform.Dispose(dOut);
 
-			byte[] bytes = bOut.ToArray();
+            byte[] bytes = bOut.ToArray();
 
 			derOut.WriteEncoded(Asn1Tags.Sequence | Asn1Tags.Constructed, bytes);
 		}
diff --git a/crypto/src/asn1/DerSet.cs b/crypto/src/asn1/DerSet.cs
index c66dde8c7..3df1a6766 100644
--- a/crypto/src/asn1/DerSet.cs
+++ b/crypto/src/asn1/DerSet.cs
@@ -1,5 +1,8 @@
+using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Asn1
 {
 	/**
@@ -98,9 +101,9 @@ namespace Org.BouncyCastle.Asn1
 				dOut.WriteObject(obj);
 			}
 
-			dOut.Close();
+            Platform.Dispose(dOut);
 
-			byte[] bytes = bOut.ToArray();
+            byte[] bytes = bOut.ToArray();
 
 			derOut.WriteEncoded(Asn1Tags.Set | Asn1Tags.Constructed, bytes);
 		}
diff --git a/crypto/src/asn1/util/Dump.cs b/crypto/src/asn1/util/Dump.cs
index 99ced5836..e313fe879 100644
--- a/crypto/src/asn1/util/Dump.cs
+++ b/crypto/src/asn1/util/Dump.cs
@@ -2,6 +2,8 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Asn1.Utilities
 {
     public sealed class Dump
@@ -21,7 +23,7 @@ namespace Org.BouncyCastle.Asn1.Utilities
                 Console.WriteLine(Asn1Dump.DumpAsString(obj));
             }
 
-			bIn.Close();
+            Platform.Dispose(bIn);
         }
     }
 }
diff --git a/crypto/src/asn1/util/FilterStream.cs b/crypto/src/asn1/util/FilterStream.cs
index 980e7f176..e280bf5b5 100644
--- a/crypto/src/asn1/util/FilterStream.cs
+++ b/crypto/src/asn1/util/FilterStream.cs
@@ -1,6 +1,8 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Asn1.Utilities
 {
     [Obsolete("Use Org.BouncyCastle.Utilities.IO.FilterStream")]
@@ -34,7 +36,7 @@ namespace Org.BouncyCastle.Asn1.Utilities
         }
         public override void Close()
         {
-            s.Close();
+            Platform.Dispose(s);
         }
         public override void Flush()
         {
diff --git a/crypto/src/bcpg/ArmoredInputStream.cs b/crypto/src/bcpg/ArmoredInputStream.cs
index 3109dd4fd..8d17bfa62 100644
--- a/crypto/src/bcpg/ArmoredInputStream.cs
+++ b/crypto/src/bcpg/ArmoredInputStream.cs
@@ -506,7 +506,7 @@ namespace Org.BouncyCastle.Bcpg
 
 		public override void Close()
 		{
-			input.Close();
+            Platform.Dispose(input);
 			base.Close();
 		}
     }
diff --git a/crypto/src/bcpg/BcpgInputStream.cs b/crypto/src/bcpg/BcpgInputStream.cs
index 2e08cd090..37c259d42 100644
--- a/crypto/src/bcpg/BcpgInputStream.cs
+++ b/crypto/src/bcpg/BcpgInputStream.cs
@@ -2,6 +2,7 @@ using System;
 using System.IO;
 
 using Org.BouncyCastle.Asn1;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Bcpg
@@ -248,7 +249,7 @@ namespace Org.BouncyCastle.Bcpg
 
 		public override void Close()
 		{
-			m_in.Close();
+            Platform.Dispose(m_in);
 			base.Close();
 		}
 
diff --git a/crypto/src/bcpg/BcpgOutputStream.cs b/crypto/src/bcpg/BcpgOutputStream.cs
index 204f65b50..581897ece 100644
--- a/crypto/src/bcpg/BcpgOutputStream.cs
+++ b/crypto/src/bcpg/BcpgOutputStream.cs
@@ -1,6 +1,7 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Bcpg
@@ -383,7 +384,7 @@ namespace Org.BouncyCastle.Bcpg
         {
 			this.Finish();
 			outStr.Flush();
-			outStr.Close();
+            Platform.Dispose(outStr);
 			base.Close();
         }
     }
diff --git a/crypto/src/bcpg/PublicKeyEncSessionPacket.cs b/crypto/src/bcpg/PublicKeyEncSessionPacket.cs
index 74d04f7aa..831b5a189 100644
--- a/crypto/src/bcpg/PublicKeyEncSessionPacket.cs
+++ b/crypto/src/bcpg/PublicKeyEncSessionPacket.cs
@@ -107,7 +107,7 @@ namespace Org.BouncyCastle.Bcpg
                 pOut.Write(data[i]);
             }
 
-            pOut.Close();
+            Platform.Dispose(pOut);
 
             bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession , bOut.ToArray(), true);
 		}
diff --git a/crypto/src/cms/CMSAuthenticatedDataGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataGenerator.cs
index 846c19a24..131a4753f 100644
--- a/crypto/src/cms/CMSAuthenticatedDataGenerator.cs
+++ b/crypto/src/cms/CMSAuthenticatedDataGenerator.cs
@@ -9,6 +9,7 @@ using Org.BouncyCastle.Crypto.Generators;
 using Org.BouncyCastle.Crypto.IO;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Cms
@@ -83,10 +84,9 @@ namespace Org.BouncyCastle.Cms
 
 				content.Write(mOut);
 
-				mOut.Close();
-				bOut.Close();
+                Platform.Dispose(mOut);
 
-				encContent = new BerOctetString(bOut.ToArray());
+                encContent = new BerOctetString(bOut.ToArray());
 
 				byte[] macOctets = MacUtilities.DoFinal(mac);
 				macResult = new DerOctetString(macOctets);
diff --git a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
index 2603cb380..a9879a6fc 100644
--- a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
@@ -9,6 +9,7 @@ using Org.BouncyCastle.Crypto.Generators;
 using Org.BouncyCastle.Crypto.IO;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Security;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Cms
@@ -253,9 +254,9 @@ namespace Org.BouncyCastle.Cms
 
 			public override void Close()
 			{
-				macStream.Close();
+                Platform.Dispose(macStream);
 
-				// TODO Parent context(s) should really be be closed explicitly
+                // TODO Parent context(s) should really be be closed explicitly
 
 				eiGen.Close();
 
diff --git a/crypto/src/cms/CMSCompressedData.cs b/crypto/src/cms/CMSCompressedData.cs
index 2d0107e88..21651f041 100644
--- a/crypto/src/cms/CMSCompressedData.cs
+++ b/crypto/src/cms/CMSCompressedData.cs
@@ -3,6 +3,7 @@ using System.IO;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Zlib;
 
 namespace Org.BouncyCastle.Cms
@@ -56,7 +57,7 @@ namespace Org.BouncyCastle.Cms
 			}
 			finally
 			{
-				zIn.Close();
+                Platform.Dispose(zIn);
 			}
         }
 
diff --git a/crypto/src/cms/CMSCompressedDataGenerator.cs b/crypto/src/cms/CMSCompressedDataGenerator.cs
index 00e2a3df4..d51de1026 100644
--- a/crypto/src/cms/CMSCompressedDataGenerator.cs
+++ b/crypto/src/cms/CMSCompressedDataGenerator.cs
@@ -5,6 +5,7 @@ using System.IO;
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
 using Org.BouncyCastle.Asn1.X509;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Zlib;
 
 namespace Org.BouncyCastle.Cms
@@ -45,9 +46,9 @@ namespace Org.BouncyCastle.Cms
 
 				content.Write(zOut);
 
-				zOut.Close();
+                Platform.Dispose(zOut);
 
-				comAlgId = new AlgorithmIdentifier(new DerObjectIdentifier(compressionOid));
+                comAlgId = new AlgorithmIdentifier(new DerObjectIdentifier(compressionOid));
 				comOcts = new BerOctetString(bOut.ToArray());
             }
             catch (IOException e)
diff --git a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
index db0d19845..73832f5f3 100644
--- a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
@@ -4,6 +4,7 @@ using System.IO;
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
 using Org.BouncyCastle.Asn1.X509;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 using Org.BouncyCastle.Utilities.Zlib;
 
@@ -126,11 +127,11 @@ namespace Org.BouncyCastle.Cms
 
 			public override void Close()
 			{
-				_out.Close();
+                Platform.Dispose(_out);
 
-				// TODO Parent context(s) should really be be closed explicitly
+                // TODO Parent context(s) should really be be closed explicitly
 
-				_eiGen.Close();
+                _eiGen.Close();
 				_cGen.Close();
 				_sGen.Close();
 				base.Close();
diff --git a/crypto/src/cms/CMSContentInfoParser.cs b/crypto/src/cms/CMSContentInfoParser.cs
index fde06cf4c..a7b43f295 100644
--- a/crypto/src/cms/CMSContentInfoParser.cs
+++ b/crypto/src/cms/CMSContentInfoParser.cs
@@ -3,6 +3,7 @@ using System.IO;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
+using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Cms
 {
@@ -41,7 +42,7 @@ namespace Org.BouncyCastle.Cms
 		*/
 		public void Close()
 		{
-			this.data.Close();
+            Platform.Dispose(this.data);
 		}
 	}
 }
diff --git a/crypto/src/cms/CMSEnvelopedDataGenerator.cs b/crypto/src/cms/CMSEnvelopedDataGenerator.cs
index 3b861cde5..d260e998a 100644
--- a/crypto/src/cms/CMSEnvelopedDataGenerator.cs
+++ b/crypto/src/cms/CMSEnvelopedDataGenerator.cs
@@ -80,9 +80,9 @@ namespace Org.BouncyCastle.Cms
 
 				content.Write(cOut);
 
-				cOut.Close();
+                Platform.Dispose(cOut);
 
-				encContent = new BerOctetString(bOut.ToArray());
+                encContent = new BerOctetString(bOut.ToArray());
 			}
 			catch (SecurityUtilityException e)
 			{
diff --git a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
index a63ea7b7f..17c49ed07 100644
--- a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
@@ -257,9 +257,9 @@ namespace Org.BouncyCastle.Cms
 
 			public override void Close()
 			{
-				_out.Close();
+                Platform.Dispose(_out);
 
-				// TODO Parent context(s) should really be be closed explicitly
+                // TODO Parent context(s) should really be be closed explicitly
 
 				_eiGen.Close();
 
diff --git a/crypto/src/cms/CMSProcessableFile.cs b/crypto/src/cms/CMSProcessableFile.cs
index 764d138f0..b514bdbda 100644
--- a/crypto/src/cms/CMSProcessableFile.cs
+++ b/crypto/src/cms/CMSProcessableFile.cs
@@ -2,6 +2,7 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Cms
@@ -37,7 +38,7 @@ namespace Org.BouncyCastle.Cms
 		{
 			Stream inStr = GetInputStream();
 			Streams.PipeAll(inStr, zOut);
-			inStr.Close();
+            Platform.Dispose(inStr);
 		}
 
         /// <returns>The file handle</returns>
diff --git a/crypto/src/cms/CMSProcessableInputStream.cs b/crypto/src/cms/CMSProcessableInputStream.cs
index 6dff7c212..b2abd6f71 100644
--- a/crypto/src/cms/CMSProcessableInputStream.cs
+++ b/crypto/src/cms/CMSProcessableInputStream.cs
@@ -1,6 +1,7 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Cms
@@ -29,7 +30,7 @@ namespace Org.BouncyCastle.Cms
 			CheckSingleUsage();
 
 			Streams.PipeAll(input, output);
-			input.Close();
+            Platform.Dispose(input);
 		}
 
         [Obsolete]
diff --git a/crypto/src/cms/CMSSignedDataGenerator.cs b/crypto/src/cms/CMSSignedDataGenerator.cs
index a80cde509..f63ed874e 100644
--- a/crypto/src/cms/CMSSignedDataGenerator.cs
+++ b/crypto/src/cms/CMSSignedDataGenerator.cs
@@ -173,7 +173,7 @@ namespace Org.BouncyCastle.Cms
 					content.Write(sigStr);
                 }
 
-				sigStr.Close();
+                Platform.Dispose(sigStr);
                 byte[] sigBytes = ((IBlockResult)calculator.GetResult()).Collect();
 
 				Asn1Set unsignedAttr = null;
diff --git a/crypto/src/cms/CMSSignedDataParser.cs b/crypto/src/cms/CMSSignedDataParser.cs
index e5674a4cf..e5e6edc58 100644
--- a/crypto/src/cms/CMSSignedDataParser.cs
+++ b/crypto/src/cms/CMSSignedDataParser.cs
@@ -384,7 +384,7 @@ namespace Org.BouncyCastle.Cms
 
 //			gen.AddSigners(parser.GetSignerInfos());
 
-			contentOut.Close();
+            Platform.Dispose(contentOut);
 
 			return outStr;
 		}
@@ -434,12 +434,12 @@ namespace Org.BouncyCastle.Cms
 
 			gen.AddSigners(parser.GetSignerInfos());
 
-			contentOut.Close();
+            Platform.Dispose(contentOut);
 
-			return outStr;
+            return outStr;
 		}
 
-		private static Asn1Set GetAsn1Set(
+        private static Asn1Set GetAsn1Set(
 			Asn1SetParser asn1SetParser)
 		{
 			return asn1SetParser == null
diff --git a/crypto/src/cms/CMSSignedDataStreamGenerator.cs b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
index 223fdb39d..746538ebd 100644
--- a/crypto/src/cms/CMSSignedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
@@ -636,7 +636,7 @@ namespace Org.BouncyCastle.Cms
 			{
 				content.Write(signedOut);
 			}
-			signedOut.Close();
+            Platform.Dispose(signedOut);
 		}
 
 		// RFC3852, section 5.1:
@@ -811,9 +811,9 @@ namespace Org.BouncyCastle.Cms
 
 			public override void Close()
             {
-                _out.Close();
+                Platform.Dispose(_out);
 
-				// TODO Parent context(s) should really be be closed explicitly
+                // TODO Parent context(s) should really be be closed explicitly
 
                 _eiGen.Close();
 
diff --git a/crypto/src/cms/CMSTypedStream.cs b/crypto/src/cms/CMSTypedStream.cs
index b7b390c4c..681583765 100644
--- a/crypto/src/cms/CMSTypedStream.cs
+++ b/crypto/src/cms/CMSTypedStream.cs
@@ -2,6 +2,7 @@ using System;
 using System.IO;
 
 using Org.BouncyCastle.Asn1.Pkcs;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
 
 namespace Org.BouncyCastle.Cms
@@ -52,7 +53,7 @@ namespace Org.BouncyCastle.Cms
 		public void Drain()
 		{
 			Streams.Drain(_in);
-			_in.Close();
+            Platform.Dispose(_in);
 		}
 
 		private class FullReaderStream : FilterStream
diff --git a/crypto/src/crypto/io/CipherStream.cs b/crypto/src/crypto/io/CipherStream.cs
index b6920854d..7fa9d3c5a 100644
--- a/crypto/src/crypto/io/CipherStream.cs
+++ b/crypto/src/crypto/io/CipherStream.cs
@@ -3,6 +3,7 @@ using System.Diagnostics;
 using System.IO;
 
 using Org.BouncyCastle.Crypto;
+using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Crypto.IO
 {
@@ -209,10 +210,10 @@ namespace Org.BouncyCastle.Crypto.IO
 				stream.Write(data, 0, data.Length);
 				stream.Flush();
 			}
-			stream.Close();
+            Platform.Dispose(stream);
         }
 
-		public override void Flush()
+        public override void Flush()
         {
 			// Note: outCipher.DoFinal is only called during Close()
 			stream.Flush();
diff --git a/crypto/src/crypto/io/DigestStream.cs b/crypto/src/crypto/io/DigestStream.cs
index c819a409a..6f31b9560 100644
--- a/crypto/src/crypto/io/DigestStream.cs
+++ b/crypto/src/crypto/io/DigestStream.cs
@@ -1,6 +1,8 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Crypto.IO
 {
 	public class DigestStream
@@ -112,10 +114,10 @@ namespace Org.BouncyCastle.Crypto.IO
 
 		public override void Close()
 		{
-			stream.Close();
+            Platform.Dispose(stream);
 		}
 
-		public override  void Flush()
+        public override  void Flush()
 		{
 			stream.Flush();
 		}
diff --git a/crypto/src/crypto/io/MacStream.cs b/crypto/src/crypto/io/MacStream.cs
index 51cf1832e..cbea1956f 100644
--- a/crypto/src/crypto/io/MacStream.cs
+++ b/crypto/src/crypto/io/MacStream.cs
@@ -1,6 +1,8 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Crypto.IO
 {
 	public class MacStream
@@ -111,10 +113,10 @@ namespace Org.BouncyCastle.Crypto.IO
 
 		public override void Close()
 		{
-			stream.Close();
+            Platform.Dispose(stream);
 		}
 
-		public override void Flush()
+        public override void Flush()
 		{
 			stream.Flush();
 		}
diff --git a/crypto/src/crypto/io/SignerStream.cs b/crypto/src/crypto/io/SignerStream.cs
index 49dfb38c6..2ff21f563 100644
--- a/crypto/src/crypto/io/SignerStream.cs
+++ b/crypto/src/crypto/io/SignerStream.cs
@@ -1,6 +1,8 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Crypto.IO
 {
 	public class SignerStream
@@ -112,10 +114,10 @@ namespace Org.BouncyCastle.Crypto.IO
 
 		public override void Close()
 		{
-			stream.Close();
+            Platform.Dispose(stream);
 		}
 
-		public override  void Flush()
+        public override  void Flush()
 		{
 			stream.Flush();
 		}
diff --git a/crypto/src/crypto/parameters/SkeinParameters.cs b/crypto/src/crypto/parameters/SkeinParameters.cs
index 9e621c09d..cc57ef5ff 100644
--- a/crypto/src/crypto/parameters/SkeinParameters.cs
+++ b/crypto/src/crypto/parameters/SkeinParameters.cs
@@ -240,7 +240,7 @@ namespace Org.BouncyCastle.Crypto.Parameters
 					outBytes.Write(emailAddress);
 					outBytes.Write(" ");
 					outBytes.Write(distinguisher);
-					outBytes.Close();
+                    Platform.Dispose(outBytes);
 					return Set(PARAM_TYPE_PERSONALISATION, bout.ToArray());
 				}
 				catch (IOException e)
diff --git a/crypto/src/crypto/tls/CertificateUrl.cs b/crypto/src/crypto/tls/CertificateUrl.cs
index a951b8063..d285fa0f6 100644
--- a/crypto/src/crypto/tls/CertificateUrl.cs
+++ b/crypto/src/crypto/tls/CertificateUrl.cs
@@ -117,7 +117,7 @@ namespace Org.BouncyCastle.Crypto.Tls
                 this.Position = 0;
                 TlsUtilities.WriteUint16((int)length, this);
                 this.WriteTo(output);
-                this.Close();
+                Platform.Dispose(this);
             }
         }
     }
diff --git a/crypto/src/crypto/tls/DtlsReliableHandshake.cs b/crypto/src/crypto/tls/DtlsReliableHandshake.cs
index 8e4439e67..7f3f832a1 100644
--- a/crypto/src/crypto/tls/DtlsReliableHandshake.cs
+++ b/crypto/src/crypto/tls/DtlsReliableHandshake.cs
@@ -420,7 +420,7 @@ namespace Org.BouncyCastle.Crypto.Tls
             internal void SendToRecordLayer(DtlsRecordLayer recordLayer)
             {
                 recordLayer.Send(GetBuffer(), 0, (int)Length);
-                this.Close();
+                Platform.Dispose(this);
             }
         }
 
diff --git a/crypto/src/crypto/tls/RecordStream.cs b/crypto/src/crypto/tls/RecordStream.cs
index 6f3fc41c6..d510ed94e 100644
--- a/crypto/src/crypto/tls/RecordStream.cs
+++ b/crypto/src/crypto/tls/RecordStream.cs
@@ -1,6 +1,8 @@
 using System;
 using System.IO;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Crypto.Tls
 {
     /// <summary>An implementation of the TLS 1.0/1.1/1.2 record layer, allowing downgrade to SSLv3.</summary>
@@ -287,7 +289,7 @@ namespace Org.BouncyCastle.Crypto.Tls
         {
             try
             {
-                mInput.Close();
+                Platform.Dispose(mInput);
             }
             catch (IOException)
             {
@@ -295,7 +297,7 @@ namespace Org.BouncyCastle.Crypto.Tls
 
             try
             {
-                mOutput.Close();
+                Platform.Dispose(mOutput);
             }
             catch (IOException)
             {
diff --git a/crypto/src/crypto/tls/TlsProtocol.cs b/crypto/src/crypto/tls/TlsProtocol.cs
index fffde0b2b..51178a473 100644
--- a/crypto/src/crypto/tls/TlsProtocol.cs
+++ b/crypto/src/crypto/tls/TlsProtocol.cs
@@ -1311,7 +1311,7 @@ namespace Org.BouncyCastle.Crypto.Tls
                 this.Position = 1;
                 TlsUtilities.WriteUint24((int)length, this);
                 protocol.WriteHandshakeMessage(GetBuffer(), 0, (int)Length);
-                this.Close();
+                Platform.Dispose(this);
             }
         }
     }
diff --git a/crypto/src/ocsp/BasicOCSPRespGenerator.cs b/crypto/src/ocsp/BasicOCSPRespGenerator.cs
index 7705071fd..0dd4e0a09 100644
--- a/crypto/src/ocsp/BasicOCSPRespGenerator.cs
+++ b/crypto/src/ocsp/BasicOCSPRespGenerator.cs
@@ -217,7 +217,7 @@ namespace Org.BouncyCastle.Ocsp
 
                 streamCalculator.Stream.Write(encoded, 0, encoded.Length);
 
-                streamCalculator.Stream.Close();
+                Platform.Dispose(streamCalculator.Stream);
 
                 bitSig = new DerBitString(((IBlockResult)streamCalculator.GetResult()).Collect());
 			}
diff --git a/crypto/src/openpgp/PgpCompressedDataGenerator.cs b/crypto/src/openpgp/PgpCompressedDataGenerator.cs
index 7f4ec8e53..c51e6326c 100644
--- a/crypto/src/openpgp/PgpCompressedDataGenerator.cs
+++ b/crypto/src/openpgp/PgpCompressedDataGenerator.cs
@@ -2,6 +2,7 @@ using System;
 using System.IO;
 
 using Org.BouncyCastle.Apache.Bzip2;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Zlib;
 
 namespace Org.BouncyCastle.Bcpg.OpenPgp
@@ -155,7 +156,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 			{
 				if (dOut != pkOut)
 				{
-					dOut.Close();
+                    Platform.Dispose(dOut);
 					dOut.Flush();
 				}
 
diff --git a/crypto/src/openpgp/PgpUtilities.cs b/crypto/src/openpgp/PgpUtilities.cs
index f982ae459..9238edcfc 100644
--- a/crypto/src/openpgp/PgpUtilities.cs
+++ b/crypto/src/openpgp/PgpUtilities.cs
@@ -382,8 +382,8 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
                 pOut.Write(buf, 0, len);
             }
 
-			pOut.Close();
-			inputStream.Close();
+            Platform.Dispose(pOut);
+            Platform.Dispose(inputStream);
 		}
 #endif
 
diff --git a/crypto/src/pkcs/Pkcs10CertificationRequest.cs b/crypto/src/pkcs/Pkcs10CertificationRequest.cs
index ce4814c23..1789f2a70 100644
--- a/crypto/src/pkcs/Pkcs10CertificationRequest.cs
+++ b/crypto/src/pkcs/Pkcs10CertificationRequest.cs
@@ -279,7 +279,7 @@ namespace Org.BouncyCastle.Pkcs
 
             streamCalculator.Stream.Write(reqInfoData, 0, reqInfoData.Length);
 
-            streamCalculator.Stream.Close();
+            Platform.Dispose(streamCalculator.Stream);
 
             // Generate Signature.
             sigBits = new DerBitString(((IBlockResult)streamCalculator.GetResult()).Collect());
@@ -342,7 +342,7 @@ namespace Org.BouncyCastle.Pkcs
 
                 streamCalculator.Stream.Write(b, 0, b.Length);
 
-                streamCalculator.Stream.Close();
+                Platform.Dispose(streamCalculator.Stream);
 
                 return ((IVerifier)streamCalculator.GetResult()).IsVerified(sigBits.GetBytes());
             }
diff --git a/crypto/src/pkix/PkixCertPath.cs b/crypto/src/pkix/PkixCertPath.cs
index 23a53c396..d03709167 100644
--- a/crypto/src/pkix/PkixCertPath.cs
+++ b/crypto/src/pkix/PkixCertPath.cs
@@ -401,7 +401,7 @@ namespace Org.BouncyCastle.Pkix
 						pWrt.WriteObject(certificates[i]);
 					}
 
-					pWrt.Writer.Close();
+                    Platform.Dispose(pWrt.Writer);
 				}
 				catch (Exception)
 				{
diff --git a/crypto/src/util/Platform.cs b/crypto/src/util/Platform.cs
index bfed0950a..82446b296 100644
--- a/crypto/src/util/Platform.cs
+++ b/crypto/src/util/Platform.cs
@@ -19,7 +19,7 @@ namespace Org.BouncyCastle.Utilities
             MemoryStream buf = new MemoryStream();
             StreamWriter w = new StreamWriter(buf, Encoding.UTF8);
             w.WriteLine();
-            w.Close();
+            Dispose(w);
             byte[] bs = buf.ToArray();
             return Encoding.UTF8.GetString(bs, 0, bs.Length);
         }
@@ -184,5 +184,21 @@ namespace Org.BouncyCastle.Utilities
         }
 
         internal static readonly string NewLine = GetNewLine();
+
+#if PORTABLE
+        internal static void Dispose(IDisposable d)
+        {
+            d.Dispose();
+        }
+#else
+        internal static void Dispose(Stream s)
+        {
+            s.Close();
+        }
+        internal static void Dispose(TextWriter t)
+        {
+            t.Close();
+        }
+#endif
     }
 }
diff --git a/crypto/src/util/io/FilterStream.cs b/crypto/src/util/io/FilterStream.cs
index 260ce1789..c5d6a1cba 100644
--- a/crypto/src/util/io/FilterStream.cs
+++ b/crypto/src/util/io/FilterStream.cs
@@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Utilities.IO
         }
         public override void Close()
         {
-            s.Close();
+            Platform.Dispose(s);
         }
         public override void Flush()
         {
diff --git a/crypto/src/util/io/TeeInputStream.cs b/crypto/src/util/io/TeeInputStream.cs
index 373df4502..b344be8a8 100644
--- a/crypto/src/util/io/TeeInputStream.cs
+++ b/crypto/src/util/io/TeeInputStream.cs
@@ -20,11 +20,11 @@ namespace Org.BouncyCastle.Utilities.IO
 
 		public override void Close()
 		{
-			input.Close();
-			tee.Close();
+            Platform.Dispose(input);
+            Platform.Dispose(tee);
 		}
 
-		public override int Read(byte[] buf, int off, int len)
+        public override int Read(byte[] buf, int off, int len)
 		{
 			int i = input.Read(buf, off, len);
 
diff --git a/crypto/src/util/io/TeeOutputStream.cs b/crypto/src/util/io/TeeOutputStream.cs
index fe3a7586a..75d1d305d 100644
--- a/crypto/src/util/io/TeeOutputStream.cs
+++ b/crypto/src/util/io/TeeOutputStream.cs
@@ -20,11 +20,11 @@ namespace Org.BouncyCastle.Utilities.IO
 
 		public override void Close()
 		{
-			output.Close();
-			tee.Close();
+            Platform.Dispose(output);
+            Platform.Dispose(tee);
 		}
 
-		public override void Write(byte[] buffer, int offset, int count)
+        public override void Write(byte[] buffer, int offset, int count)
 		{
 			output.Write(buffer, offset, count);
 			tee.Write(buffer, offset, count);
diff --git a/crypto/src/util/zlib/ZDeflaterOutputStream.cs b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
index 1d88847bd..7ff6d31c8 100644
--- a/crypto/src/util/zlib/ZDeflaterOutputStream.cs
+++ b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
@@ -143,7 +143,7 @@ namespace Org.BouncyCastle.Utilities.Zlib {
             }
             finally{
                 End();
-                outp.Close();
+                Platform.Dispose(outp);
                 outp=null;
             }
         }
diff --git a/crypto/src/util/zlib/ZInflaterInputStream.cs b/crypto/src/util/zlib/ZInflaterInputStream.cs
index 5a3ff5aa6..170596e63 100644
--- a/crypto/src/util/zlib/ZInflaterInputStream.cs
+++ b/crypto/src/util/zlib/ZInflaterInputStream.cs
@@ -115,7 +115,7 @@ namespace Org.BouncyCastle.Utilities.Zlib {
         }
 
         public override void Close() {
-            inp.Close();
+            Platform.Dispose(inp);
         }
     
         public override int ReadByte() {
diff --git a/crypto/src/util/zlib/ZInputStream.cs b/crypto/src/util/zlib/ZInputStream.cs
index d1e1ba160..f0b3068fc 100644
--- a/crypto/src/util/zlib/ZInputStream.cs
+++ b/crypto/src/util/zlib/ZInputStream.cs
@@ -98,7 +98,7 @@ namespace Org.BouncyCastle.Utilities.Zlib
 			if (!closed)
 			{
 				closed = true;
-				input.Close();
+                Platform.Dispose(input);
 			}
 		}
 
diff --git a/crypto/src/util/zlib/ZOutputStream.cs b/crypto/src/util/zlib/ZOutputStream.cs
index 1d2ead7b3..7b49d6638 100644
--- a/crypto/src/util/zlib/ZOutputStream.cs
+++ b/crypto/src/util/zlib/ZOutputStream.cs
@@ -115,7 +115,7 @@ namespace Org.BouncyCastle.Utilities.Zlib
 			{
 				this.closed = true;
 				End();
-				output.Close();
+                Platform.Dispose(output);
 				output = null;
 			}
 		}
diff --git a/crypto/src/x509/X509Certificate.cs b/crypto/src/x509/X509Certificate.cs
index 9c65f095a..fc7f96aa9 100644
--- a/crypto/src/x509/X509Certificate.cs
+++ b/crypto/src/x509/X509Certificate.cs
@@ -576,7 +576,7 @@ namespace Org.BouncyCastle.X509
 
 			streamCalculator.Stream.Write(b, 0, b.Length);
 
-            streamCalculator.Stream.Close();
+            Platform.Dispose(streamCalculator.Stream);
 
             if (!((IVerifier)streamCalculator.GetResult()).IsVerified(this.GetSignature()))
 			{
diff --git a/crypto/src/x509/X509Crl.cs b/crypto/src/x509/X509Crl.cs
index 087aab23c..53de3e91f 100644
--- a/crypto/src/x509/X509Crl.cs
+++ b/crypto/src/x509/X509Crl.cs
@@ -115,7 +115,7 @@ namespace Org.BouncyCastle.X509
 
             streamCalculator.Stream.Write(b, 0, b.Length);
 
-            streamCalculator.Stream.Close();
+            Platform.Dispose(streamCalculator.Stream);
 
             if (!((IVerifier)streamCalculator.GetResult()).IsVerified(this.GetSignature()))
             {
diff --git a/crypto/src/x509/X509V1CertificateGenerator.cs b/crypto/src/x509/X509V1CertificateGenerator.cs
index 79e3862e4..9adebcb16 100644
--- a/crypto/src/x509/X509V1CertificateGenerator.cs
+++ b/crypto/src/x509/X509V1CertificateGenerator.cs
@@ -10,6 +10,7 @@ using Org.BouncyCastle.Crypto.Operators;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Security;
 using Org.BouncyCastle.Security.Certificates;
+using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.X509
 {
@@ -184,7 +185,7 @@ namespace Org.BouncyCastle.X509
 
             streamCalculator.Stream.Write(encoded, 0, encoded.Length);
 
-            streamCalculator.Stream.Close();
+            Platform.Dispose(streamCalculator.Stream);
 
             return GenerateJcaObject(tbsCert, (AlgorithmIdentifier)signatureCalculatorFactory.AlgorithmDetails, ((IBlockResult)streamCalculator.GetResult()).Collect());
 		}
diff --git a/crypto/src/x509/X509V2AttributeCertificate.cs b/crypto/src/x509/X509V2AttributeCertificate.cs
index 9de9cb538..9376538a1 100644
--- a/crypto/src/x509/X509V2AttributeCertificate.cs
+++ b/crypto/src/x509/X509V2AttributeCertificate.cs
@@ -5,11 +5,11 @@ using System.IO;
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
+using Org.BouncyCastle.Crypto.Operators;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Security;
 using Org.BouncyCastle.Security.Certificates;
 using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Crypto.Operators;
 
 namespace Org.BouncyCastle.X509
 {
@@ -186,7 +186,7 @@ namespace Org.BouncyCastle.X509
 
                 streamCalculator.Stream.Write(b, 0, b.Length);
 
-                streamCalculator.Stream.Close();
+                Platform.Dispose(streamCalculator.Stream);
             }
 			catch (IOException e)
 			{
diff --git a/crypto/src/x509/X509V2AttributeCertificateGenerator.cs b/crypto/src/x509/X509V2AttributeCertificateGenerator.cs
index 8fd5dfdb9..bf046cd1e 100644
--- a/crypto/src/x509/X509V2AttributeCertificateGenerator.cs
+++ b/crypto/src/x509/X509V2AttributeCertificateGenerator.cs
@@ -1,15 +1,15 @@
 using System;
 using System.Collections;
+using System.IO;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
+using Org.BouncyCastle.Crypto.Operators;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Security;
 using Org.BouncyCastle.Security.Certificates;
 using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Crypto.Operators;
-using System.IO;
 
 namespace Org.BouncyCastle.X509
 {
@@ -172,7 +172,7 @@ namespace Org.BouncyCastle.X509
 
             streamCalculator.Stream.Write(encoded, 0, encoded.Length);
 
-            streamCalculator.Stream.Close();
+            Platform.Dispose(streamCalculator.Stream);
 
             Asn1EncodableVector v = new Asn1EncodableVector();
 
diff --git a/crypto/src/x509/X509V2CRLGenerator.cs b/crypto/src/x509/X509V2CRLGenerator.cs
index 6c9ffe7e5..566d50234 100644
--- a/crypto/src/x509/X509V2CRLGenerator.cs
+++ b/crypto/src/x509/X509V2CRLGenerator.cs
@@ -5,12 +5,13 @@ using System.IO;
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
+using Org.BouncyCastle.Crypto.Operators;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Security;
 using Org.BouncyCastle.Security.Certificates;
+using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.Collections;
-using Org.BouncyCastle.Crypto.Operators;
 
 namespace Org.BouncyCastle.X509
 {
@@ -241,7 +242,7 @@ namespace Org.BouncyCastle.X509
 
             streamCalculator.Stream.Write(encoded, 0, encoded.Length);
 
-            streamCalculator.Stream.Close();
+            Platform.Dispose(streamCalculator.Stream);
 
             return GenerateJcaObject(tbsCertList, (AlgorithmIdentifier)signatureCalculatorFactory.AlgorithmDetails, ((IBlockResult)streamCalculator.GetResult()).Collect());
         }