diff options
Diffstat (limited to 'crypto')
30 files changed, 515 insertions, 71 deletions
diff --git a/crypto/bzip2/src/CBZip2OutputStream.cs b/crypto/bzip2/src/CBZip2OutputStream.cs index 73e6979d8..15e816f3a 100644 --- a/crypto/bzip2/src/CBZip2OutputStream.cs +++ b/crypto/bzip2/src/CBZip2OutputStream.cs @@ -386,6 +386,21 @@ namespace Org.BouncyCastle.Apache.Bzip2 // Close(); // } +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + if (closed) + return; + + Finish(); + closed = true; + Platform.Dispose(this.bsStream); + } + base.Dispose(disposing); + } +#else public override void Close() { if (closed) { return; @@ -397,6 +412,7 @@ namespace Org.BouncyCastle.Apache.Bzip2 base.Close(); Platform.Dispose(this.bsStream); } +#endif public void Finish() { if (finished) { diff --git a/crypto/src/asn1/BEROctetStringGenerator.cs b/crypto/src/asn1/BEROctetStringGenerator.cs index 7468a6b0b..b2fbd47ae 100644 --- a/crypto/src/asn1/BEROctetStringGenerator.cs +++ b/crypto/src/asn1/BEROctetStringGenerator.cs @@ -102,7 +102,22 @@ namespace Org.BouncyCastle.Asn1 } } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + if (_off != 0) + { + DerOctetString.Encode(_derOut, _buf, 0, _off); + } + + _gen.WriteBerEnd(); + } + base.Dispose(disposing); + } +#else + public override void Close() { if (_off != 0) { @@ -112,6 +127,7 @@ namespace Org.BouncyCastle.Asn1 _gen.WriteBerEnd(); base.Close(); } +#endif } } } diff --git a/crypto/src/asn1/util/FilterStream.cs b/crypto/src/asn1/util/FilterStream.cs index e280bf5b5..f7e8708f3 100644 --- a/crypto/src/asn1/util/FilterStream.cs +++ b/crypto/src/asn1/util/FilterStream.cs @@ -34,10 +34,21 @@ namespace Org.BouncyCastle.Asn1.Utilities 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/bcpg/ArmoredInputStream.cs b/crypto/src/bcpg/ArmoredInputStream.cs index 8d17bfa62..cfbf819e0 100644 --- a/crypto/src/bcpg/ArmoredInputStream.cs +++ b/crypto/src/bcpg/ArmoredInputStream.cs @@ -504,10 +504,21 @@ namespace Org.BouncyCastle.Bcpg return pos - offset; } +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Platform.Dispose(input); + } + base.Dispose(disposing); + } +#else public override void Close() { Platform.Dispose(input); base.Close(); } +#endif } } diff --git a/crypto/src/bcpg/ArmoredOutputStream.cs b/crypto/src/bcpg/ArmoredOutputStream.cs index 253c5d1fe..0f0d6896c 100644 --- a/crypto/src/bcpg/ArmoredOutputStream.cs +++ b/crypto/src/bcpg/ArmoredOutputStream.cs @@ -283,37 +283,60 @@ namespace Org.BouncyCastle.Bcpg * <b>Note</b>: Close() does not close the underlying stream. So it is possible to write * multiple objects using armoring to a single stream. */ - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) { - if (type != null) + if (disposing) { - if (bufPtr > 0) - { - Encode(outStream, buf, bufPtr); - } + if (type == null) + return; - DoWrite(nl + '='); + DoClose(); - int crcV = crc.Value; - - buf[0] = ((crcV >> 16) & 0xff); - buf[1] = ((crcV >> 8) & 0xff); - buf[2] = (crcV & 0xff); + type = null; + start = true; + } + base.Dispose(disposing); + } +#else + public override void Close() + { + if (type == null) + return; - Encode(outStream, buf, 3); + DoClose(); - DoWrite(nl); - DoWrite(footerStart); - DoWrite(type); - DoWrite(footerTail); - DoWrite(nl); + type = null; + start = true; - outStream.Flush(); + base.Close(); + } +#endif - type = null; - start = true; - base.Close(); + private void DoClose() + { + if (bufPtr > 0) + { + Encode(outStream, buf, bufPtr); } + + DoWrite(nl + '='); + + int crcV = crc.Value; + + buf[0] = ((crcV >> 16) & 0xff); + buf[1] = ((crcV >> 8) & 0xff); + buf[2] = (crcV & 0xff); + + Encode(outStream, buf, 3); + + DoWrite(nl); + DoWrite(footerStart); + DoWrite(type); + DoWrite(footerTail); + DoWrite(nl); + + outStream.Flush(); } private void WriteHeaderEntry( diff --git a/crypto/src/bcpg/BcpgInputStream.cs b/crypto/src/bcpg/BcpgInputStream.cs index 37c259d42..59dd548ca 100644 --- a/crypto/src/bcpg/BcpgInputStream.cs +++ b/crypto/src/bcpg/BcpgInputStream.cs @@ -247,11 +247,22 @@ namespace Org.BouncyCastle.Bcpg } } +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Platform.Dispose(m_in); + } + base.Dispose(disposing); + } +#else public override void Close() { Platform.Dispose(m_in); base.Close(); } +#endif /// <summary> /// A stream that overlays our input stream, allowing the user to only read a segment of it. diff --git a/crypto/src/bcpg/BcpgOutputStream.cs b/crypto/src/bcpg/BcpgOutputStream.cs index 581897ece..c786a8fc0 100644 --- a/crypto/src/bcpg/BcpgOutputStream.cs +++ b/crypto/src/bcpg/BcpgOutputStream.cs @@ -380,12 +380,25 @@ namespace Org.BouncyCastle.Bcpg } } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + this.Finish(); + outStr.Flush(); + Platform.Dispose(outStr); + } + base.Dispose(disposing); + } +#else + public override void Close() { this.Finish(); outStr.Flush(); Platform.Dispose(outStr); base.Close(); } +#endif } } diff --git a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs index a9879a6fc..591e36f2d 100644 --- a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs @@ -252,7 +252,29 @@ namespace Org.BouncyCastle.Cms macStream.Write(bytes, off, len); } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Platform.Dispose(macStream); + + // TODO Parent context(s) should really be be closed explicitly + + eiGen.Close(); + + // [TODO] auth attributes go here + byte[] macOctets = MacUtilities.DoFinal(mac); + authGen.AddObject(new DerOctetString(macOctets)); + // [TODO] unauth attributes go here + + authGen.Close(); + cGen.Close(); + } + base.Dispose(disposing); + } +#else + public override void Close() { Platform.Dispose(macStream); @@ -268,6 +290,7 @@ namespace Org.BouncyCastle.Cms authGen.Close(); cGen.Close(); } +#endif } } } diff --git a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs index 73832f5f3..1fb8da756 100644 --- a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs @@ -125,7 +125,23 @@ namespace Org.BouncyCastle.Cms _out.Write(bytes, off, len); } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Platform.Dispose(_out); + + // TODO Parent context(s) should really be be closed explicitly + + _eiGen.Close(); + _cGen.Close(); + _sGen.Close(); + } + base.Dispose(disposing); + } +#else + public override void Close() { Platform.Dispose(_out); @@ -136,6 +152,7 @@ namespace Org.BouncyCastle.Cms _sGen.Close(); base.Close(); } +#endif } } } diff --git a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs index 17c49ed07..264161b73 100644 --- a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs @@ -255,11 +255,37 @@ namespace Org.BouncyCastle.Cms _out.Write(bytes, off, len); } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Platform.Dispose(_out); + + // TODO Parent context(s) should really be closed explicitly + + _eiGen.Close(); + + if (_outer.unprotectedAttributeGenerator != null) + { + Asn1.Cms.AttributeTable attrTable = _outer.unprotectedAttributeGenerator.GetAttributes(Platform.CreateHashtable()); + + Asn1Set unprotectedAttrs = new BerSet(attrTable.ToAsn1EncodableVector()); + + _envGen.AddObject(new DerTaggedObject(false, 1, unprotectedAttrs)); + } + + _envGen.Close(); + _cGen.Close(); + } + base.Dispose(disposing); + } +#else + public override void Close() { Platform.Dispose(_out); - // TODO Parent context(s) should really be be closed explicitly + // TODO Parent context(s) should really be closed explicitly _eiGen.Close(); @@ -276,6 +302,7 @@ namespace Org.BouncyCastle.Cms _cGen.Close(); base.Close(); } +#endif } } } diff --git a/crypto/src/cms/CMSSignedDataStreamGenerator.cs b/crypto/src/cms/CMSSignedDataStreamGenerator.cs index 746538ebd..36e7a780c 100644 --- a/crypto/src/cms/CMSSignedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSSignedDataStreamGenerator.cs @@ -809,8 +809,25 @@ namespace Org.BouncyCastle.Cms _out.Write(bytes, off, len); } +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + DoClose(); + } + base.Dispose(disposing); + } +#else public override void Close() { + DoClose(); + base.Close(); + } +#endif + + private void DoClose() + { Platform.Dispose(_out); // TODO Parent context(s) should really be be closed explicitly @@ -898,8 +915,7 @@ namespace Org.BouncyCastle.Cms _sigGen.Close(); _sGen.Close(); - base.Close(); - } + } private static void WriteToGenerator( Asn1Generator ag, diff --git a/crypto/src/crypto/io/CipherStream.cs b/crypto/src/crypto/io/CipherStream.cs index 7fa9d3c5a..273413ea0 100644 --- a/crypto/src/crypto/io/CipherStream.cs +++ b/crypto/src/crypto/io/CipherStream.cs @@ -202,7 +202,23 @@ namespace Org.BouncyCastle.Crypto.IO set { throw new NotSupportedException(); } } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + if (outCipher != null) + { + byte[] data = outCipher.DoFinal(); + stream.Write(data, 0, data.Length); + stream.Flush(); + } + Platform.Dispose(stream); + } + base.Dispose(disposing); + } +#else + public override void Close() { if (outCipher != null) { @@ -212,6 +228,7 @@ namespace Org.BouncyCastle.Crypto.IO } Platform.Dispose(stream); } +#endif public override void Flush() { diff --git a/crypto/src/crypto/io/DigestStream.cs b/crypto/src/crypto/io/DigestStream.cs index 6f31b9560..3f5716d15 100644 --- a/crypto/src/crypto/io/DigestStream.cs +++ b/crypto/src/crypto/io/DigestStream.cs @@ -112,12 +112,23 @@ namespace Org.BouncyCastle.Crypto.IO set { stream.Position = value; } } +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Platform.Dispose(stream); + } + base.Dispose(disposing); + } +#else public override void Close() { Platform.Dispose(stream); } +#endif - 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 cbea1956f..f15e6d45a 100644 --- a/crypto/src/crypto/io/MacStream.cs +++ b/crypto/src/crypto/io/MacStream.cs @@ -111,10 +111,21 @@ namespace Org.BouncyCastle.Crypto.IO set { stream.Position = value; } } - public override void Close() - { +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Platform.Dispose(stream); + } + base.Dispose(disposing); + } +#else + public override void Close() + { Platform.Dispose(stream); - } + } +#endif public override void Flush() { diff --git a/crypto/src/crypto/io/SignerStream.cs b/crypto/src/crypto/io/SignerStream.cs index 2ff21f563..b9fadfc77 100644 --- a/crypto/src/crypto/io/SignerStream.cs +++ b/crypto/src/crypto/io/SignerStream.cs @@ -112,10 +112,21 @@ namespace Org.BouncyCastle.Crypto.IO set { stream.Position = value; } } - public override void Close() - { +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Platform.Dispose(stream); + } + base.Dispose(disposing); + } +#else + public override void Close() + { Platform.Dispose(stream); - } + } +#endif public override void Flush() { diff --git a/crypto/src/crypto/operators/Asn1Signature.cs b/crypto/src/crypto/operators/Asn1Signature.cs index d7af3ab13..311711e20 100644 --- a/crypto/src/crypto/operators/Asn1Signature.cs +++ b/crypto/src/crypto/operators/Asn1Signature.cs @@ -303,9 +303,19 @@ namespace Org.BouncyCastle.Crypto.Operators set { throw new NotImplementedException (); } } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + return; + + base.Dispose(disposing); + } +#else + public override void Close() { } +#endif public override void Flush() { diff --git a/crypto/src/crypto/tls/ByteQueueStream.cs b/crypto/src/crypto/tls/ByteQueueStream.cs index bf603e006..9a8ca7d92 100644 --- a/crypto/src/crypto/tls/ByteQueueStream.cs +++ b/crypto/src/crypto/tls/ByteQueueStream.cs @@ -33,9 +33,19 @@ namespace Org.BouncyCastle.Crypto.Tls get { return true; } } +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + return; + + base.Dispose(disposing); + } +#else public override void Close() { } +#endif public override void Flush() { diff --git a/crypto/src/crypto/tls/TlsStream.cs b/crypto/src/crypto/tls/TlsStream.cs index 7ff7184e3..bc2201cdb 100644 --- a/crypto/src/crypto/tls/TlsStream.cs +++ b/crypto/src/crypto/tls/TlsStream.cs @@ -28,10 +28,21 @@ namespace Org.BouncyCastle.Crypto.Tls get { return !handler.IsClosed; } } +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + handler.Close(); + } + base.Dispose(disposing); + } +#else public override void Close() { handler.Close(); } +#endif public override void Flush() { diff --git a/crypto/src/openpgp/PgpCompressedDataGenerator.cs b/crypto/src/openpgp/PgpCompressedDataGenerator.cs index 307fdbf08..ea366e0c6 100644 --- a/crypto/src/openpgp/PgpCompressedDataGenerator.cs +++ b/crypto/src/openpgp/PgpCompressedDataGenerator.cs @@ -173,10 +173,21 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Finish(); + } + base.Dispose(disposing); + } +#else + public override void Close() { Finish(); } +#endif } private class SafeZOutputStream : ZOutputStream @@ -186,11 +197,23 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { } - public override void Close() +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + Finish(); + End(); + } + base.Dispose(disposing); + } +#else + public override void Close() { Finish(); End(); } +#endif } } } diff --git a/crypto/src/openpgp/WrappedGeneratorStream.cs b/crypto/src/openpgp/WrappedGeneratorStream.cs index cdc9befb3..ffa199255 100644 --- a/crypto/src/openpgp/WrappedGeneratorStream.cs +++ b/crypto/src/openpgp/WrappedGeneratorStream.cs @@ -17,9 +17,21 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp this.gen = gen; } +#if PORTABLE + protected override void Disposing(bool disposing) + { + if (disposing) + { + gen.Close(); + return; + } + base.Dispose(disposing); + } +#else public override void Close() { gen.Close(); } +#endif } } 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; diff --git a/crypto/test/src/util/test/UncloseableStream.cs b/crypto/test/src/util/test/UncloseableStream.cs index 171198120..2a3b4229b 100644 --- a/crypto/test/src/util/test/UncloseableStream.cs +++ b/crypto/test/src/util/test/UncloseableStream.cs @@ -14,9 +14,21 @@ namespace Org.BouncyCastle.Utilities.Test { } - public override void Close() +#if PORTABLE + protected override void Dispose(bool disposing) + { + if (disposing) + { + throw new Exception("UncloseableStream was disposed"); + } + + base.Dispose(disposing); + } +#else + public override void Close() { throw new Exception("Close() called on UncloseableStream"); } - } +#endif + } } |