diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-30 10:33:35 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-30 10:33:35 +0700 |
commit | 1d31e90574c9dc8060670773a99c8a9ea5b2827c (patch) | |
tree | 50c520a5e0bd14dab5e5ad85cdc5dd5e8928ff56 /crypto/src/openpgp/WrappedGeneratorStream.cs | |
parent | Cleanup Stream disposing in Bcpg (diff) | |
download | BouncyCastle.NET-ed25519-1d31e90574c9dc8060670773a99c8a9ea5b2827c.tar.xz |
Some PORTABLE cleanup
Diffstat (limited to 'crypto/src/openpgp/WrappedGeneratorStream.cs')
-rw-r--r-- | crypto/src/openpgp/WrappedGeneratorStream.cs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/crypto/src/openpgp/WrappedGeneratorStream.cs b/crypto/src/openpgp/WrappedGeneratorStream.cs index 5f4a4b045..df31d71f0 100644 --- a/crypto/src/openpgp/WrappedGeneratorStream.cs +++ b/crypto/src/openpgp/WrappedGeneratorStream.cs @@ -1,37 +1,41 @@ +using System; using System.IO; using Org.BouncyCastle.Utilities.IO; namespace Org.BouncyCastle.Bcpg.OpenPgp { - public class WrappedGeneratorStream + internal sealed class WrappedGeneratorStream : FilterStream { - private readonly IStreamGenerator gen; + private IStreamGenerator m_generator; - public WrappedGeneratorStream( - IStreamGenerator gen, - Stream str) - : base(str) + internal WrappedGeneratorStream(IStreamGenerator generator, Stream s) + : base(s) { - this.gen = gen; + if (generator == null) + throw new ArgumentNullException(nameof(generator)); + + m_generator = generator; } -#if PORTABLE protected override void Dispose(bool disposing) { - if (disposing) + if (m_generator != null) + { + if (disposing) + { + m_generator.Close(); + } + + m_generator = null; + } + + // Don't dispose the wrapped Stream + if (!disposing) { - gen.Close(); - return; - } - base.Dispose(disposing); - } -#else - public override void Close() - { - gen.Close(); + base.Dispose(disposing); + } } -#endif } } |