summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/AssemblyInfo.cs3
-rw-r--r--crypto/src/asn1/DerSequence.cs2
-rw-r--r--crypto/src/asn1/DerSet.cs2
-rw-r--r--crypto/src/asn1/util/FilterStream.cs10
-rw-r--r--crypto/src/bcpg/ArmoredInputStream.cs13
-rw-r--r--crypto/src/bcpg/ArmoredOutputStream.cs50
-rw-r--r--crypto/src/bcpg/BcpgInputStream.cs13
-rw-r--r--crypto/src/bcpg/BcpgOutputStream.cs17
-rw-r--r--crypto/src/cms/CMSAuthenticatedDataGenerator.cs4
-rw-r--r--crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs36
-rw-r--r--crypto/src/cms/CMSCompressedData.cs2
-rw-r--r--crypto/src/cms/CMSCompressedDataStreamGenerator.cs25
-rw-r--r--crypto/src/cms/CMSContentInfoParser.cs2
-rw-r--r--crypto/src/cms/CMSEnvelopedDataGenerator.cs2
-rw-r--r--crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs33
-rw-r--r--crypto/src/cms/CMSProcessableInputStream.cs2
-rw-r--r--crypto/src/cms/CMSSignedDataGenerator.cs2
-rw-r--r--crypto/src/cms/CMSSignedDataParser.cs4
-rw-r--r--crypto/src/cms/CMSSignedDataStreamGenerator.cs155
-rw-r--r--crypto/src/cms/CMSTypedStream.cs2
-rw-r--r--crypto/src/crypto/engines/NaccacheSternEngine.cs41
-rw-r--r--crypto/src/crypto/generators/NaccacheSternKeyPairGenerator.cs54
-rw-r--r--crypto/src/crypto/io/CipherStream.cs20
-rw-r--r--crypto/src/crypto/io/DigestStream.cs12
-rw-r--r--crypto/src/crypto/io/MacStream.cs12
-rw-r--r--crypto/src/crypto/io/SignerStream.cs12
-rw-r--r--crypto/src/crypto/modes/CcmBlockCipher.cs4
-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/HeartbeatMessage.cs2
-rw-r--r--crypto/src/crypto/tls/RecordStream.cs4
-rw-r--r--crypto/src/crypto/tls/TlsProtocol.cs4
-rw-r--r--crypto/src/crypto/tls/TlsStream.cs8
-rw-r--r--crypto/src/openpgp/PgpCompressedDataGenerator.cs14
-rw-r--r--crypto/src/openpgp/WrappedGeneratorStream.cs12
-rw-r--r--crypto/src/pkcs/Pkcs12Store.cs13
-rw-r--r--crypto/src/pkix/PkixCertPath.cs2
-rw-r--r--crypto/src/util/Enums.cs2
-rw-r--r--crypto/src/util/io/BaseInputStream.cs13
-rw-r--r--crypto/src/util/io/BaseOutputStream.cs9
-rw-r--r--crypto/src/util/io/TeeInputStream.cs14
-rw-r--r--crypto/src/util/io/TeeOutputStream.cs16
-rw-r--r--crypto/src/util/zlib/ZDeflaterOutputStream.cs27
-rw-r--r--crypto/src/util/zlib/ZInflaterInputStream.cs9
-rw-r--r--crypto/src/util/zlib/ZInputStream.cs20
-rw-r--r--crypto/src/util/zlib/ZOutputStream.cs54
46 files changed, 434 insertions, 327 deletions
diff --git a/crypto/src/AssemblyInfo.cs b/crypto/src/AssemblyInfo.cs

index 7dd625878..374e590cc 100644 --- a/crypto/src/AssemblyInfo.cs +++ b/crypto/src/AssemblyInfo.cs
@@ -65,8 +65,9 @@ using System.Runtime.InteropServices; [assembly: AssemblyKeyName("")] [assembly: CLSCompliant(true)] +#if !PCL [assembly: ComVisible(false)] - +#endif // Start with no permissions //[assembly: PermissionSet(SecurityAction.RequestOptional, Unrestricted=false)] //...and explicitly add those we need diff --git a/crypto/src/asn1/DerSequence.cs b/crypto/src/asn1/DerSequence.cs
index b50a77962..1a86dc429 100644 --- a/crypto/src/asn1/DerSequence.cs +++ b/crypto/src/asn1/DerSequence.cs
@@ -75,7 +75,7 @@ namespace Org.BouncyCastle.Asn1 dOut.WriteObject(obj); } - dOut.Close(); + dOut.Dispose(); byte[] bytes = bOut.ToArray(); diff --git a/crypto/src/asn1/DerSet.cs b/crypto/src/asn1/DerSet.cs
index c66dde8c7..6d3f438bd 100644 --- a/crypto/src/asn1/DerSet.cs +++ b/crypto/src/asn1/DerSet.cs
@@ -98,7 +98,7 @@ namespace Org.BouncyCastle.Asn1 dOut.WriteObject(obj); } - dOut.Close(); + dOut.Dispose(); byte[] bytes = bOut.ToArray(); diff --git a/crypto/src/asn1/util/FilterStream.cs b/crypto/src/asn1/util/FilterStream.cs
index 2b0494b78..2b22856a6 100644 --- a/crypto/src/asn1/util/FilterStream.cs +++ b/crypto/src/asn1/util/FilterStream.cs
@@ -30,10 +30,16 @@ namespace Org.BouncyCastle.Asn1.Utilities get { return s.Position; } set { s.Position = value; } } - public override void Close() + + protected override void Dispose(bool disposing) { - s.Close(); + if (disposing) + { + s.Dispose(); + } + base.Dispose(disposing); } + public override void Flush() { s.Flush(); diff --git a/crypto/src/bcpg/ArmoredInputStream.cs b/crypto/src/bcpg/ArmoredInputStream.cs
index 3109dd4fd..c7bb85942 100644 --- a/crypto/src/bcpg/ArmoredInputStream.cs +++ b/crypto/src/bcpg/ArmoredInputStream.cs
@@ -504,10 +504,13 @@ namespace Org.BouncyCastle.Bcpg return pos - offset; } - public override void Close() - { - input.Close(); - base.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + input.Dispose(); + } + base.Dispose(disposing); + } } } diff --git a/crypto/src/bcpg/ArmoredOutputStream.cs b/crypto/src/bcpg/ArmoredOutputStream.cs
index b3a32c6f5..801e06205 100644 --- a/crypto/src/bcpg/ArmoredOutputStream.cs +++ b/crypto/src/bcpg/ArmoredOutputStream.cs
@@ -98,7 +98,8 @@ namespace Org.BouncyCastle.Bcpg private static readonly string footerTail = "-----"; private static readonly string version = "BCPG C# v" - + Assembly.GetExecutingAssembly().GetName().Version; + + Assembly.GetExecutingAssembly() + .FullName;//.GetName().Version; private readonly IDictionary headers; @@ -280,37 +281,40 @@ namespace Org.BouncyCastle.Bcpg * <b>Note</b>: close does nor close the underlying stream. So it is possible to write * multiple objects using armoring to a single stream. */ - public override void Close() + protected override void Dispose(bool disposing) { - if (type != null) + if (disposing) { - if (bufPtr > 0) - { - Encode(outStream, buf, bufPtr); - } + if (type != null) + { + if (bufPtr > 0) + { + Encode(outStream, buf, bufPtr); + } - DoWrite(nl + '='); + DoWrite(nl + '='); - int crcV = crc.Value; + int crcV = crc.Value; - buf[0] = ((crcV >> 16) & 0xff); - buf[1] = ((crcV >> 8) & 0xff); - buf[2] = (crcV & 0xff); + buf[0] = ((crcV >> 16) & 0xff); + buf[1] = ((crcV >> 8) & 0xff); + buf[2] = (crcV & 0xff); - Encode(outStream, buf, 3); + Encode(outStream, buf, 3); - DoWrite(nl); - DoWrite(footerStart); - DoWrite(type); - DoWrite(footerTail); - DoWrite(nl); + DoWrite(nl); + DoWrite(footerStart); + DoWrite(type); + DoWrite(footerTail); + DoWrite(nl); - outStream.Flush(); + outStream.Flush(); - type = null; - start = true; - base.Close(); - } + type = null; + start = true; + } + } + base.Dispose(disposing); } private void WriteHeaderEntry( diff --git a/crypto/src/bcpg/BcpgInputStream.cs b/crypto/src/bcpg/BcpgInputStream.cs
index 3c69fbdf5..e8a4f048d 100644 --- a/crypto/src/bcpg/BcpgInputStream.cs +++ b/crypto/src/bcpg/BcpgInputStream.cs
@@ -250,11 +250,14 @@ namespace Org.BouncyCastle.Bcpg } } - public override void Close() - { - m_in.Close(); - base.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + m_in.Dispose(); + } + base.Dispose(disposing); + } /// <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 204f65b50..c9545dc65 100644 --- a/crypto/src/bcpg/BcpgOutputStream.cs +++ b/crypto/src/bcpg/BcpgOutputStream.cs
@@ -379,12 +379,15 @@ namespace Org.BouncyCastle.Bcpg } } - public override void Close() - { - this.Finish(); - outStr.Flush(); - outStr.Close(); - base.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + this.Finish(); + outStr.Flush(); + outStr.Dispose(); + } + base.Dispose(disposing); + } } } diff --git a/crypto/src/cms/CMSAuthenticatedDataGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataGenerator.cs
index 846c19a24..0a37ca4f5 100644 --- a/crypto/src/cms/CMSAuthenticatedDataGenerator.cs +++ b/crypto/src/cms/CMSAuthenticatedDataGenerator.cs
@@ -83,8 +83,8 @@ namespace Org.BouncyCastle.Cms content.Write(mOut); - mOut.Close(); - bOut.Close(); + mOut.Dispose(); + bOut.Dispose(); encContent = new BerOctetString(bOut.ToArray()); diff --git a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
index 2603cb380..6638ccff7 100644 --- a/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSAuthenticatedDataStreamGenerator.cs
@@ -251,22 +251,26 @@ namespace Org.BouncyCastle.Cms macStream.Write(bytes, off, len); } - public override void Close() - { - macStream.Close(); - - // 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(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + macStream.Dispose(); + + // 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); + } } } } diff --git a/crypto/src/cms/CMSCompressedData.cs b/crypto/src/cms/CMSCompressedData.cs
index 2d0107e88..a351d7206 100644 --- a/crypto/src/cms/CMSCompressedData.cs +++ b/crypto/src/cms/CMSCompressedData.cs
@@ -56,7 +56,7 @@ namespace Org.BouncyCastle.Cms } finally { - zIn.Close(); + zIn.Dispose(); } } diff --git a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
index db0d19845..b817d3ae1 100644 --- a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
@@ -124,17 +124,20 @@ namespace Org.BouncyCastle.Cms _out.Write(bytes, off, len); } - public override void Close() - { - _out.Close(); - - // TODO Parent context(s) should really be be closed explicitly - - _eiGen.Close(); - _cGen.Close(); - _sGen.Close(); - base.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + _out.Close(); + + // TODO Parent context(s) should really be be closed explicitly + + _eiGen.Close(); + _cGen.Close(); + _sGen.Close(); + } + base.Dispose(disposing); + } } } } diff --git a/crypto/src/cms/CMSContentInfoParser.cs b/crypto/src/cms/CMSContentInfoParser.cs
index fde06cf4c..5b1606394 100644 --- a/crypto/src/cms/CMSContentInfoParser.cs +++ b/crypto/src/cms/CMSContentInfoParser.cs
@@ -41,7 +41,7 @@ namespace Org.BouncyCastle.Cms */ public void Close() { - this.data.Close(); + this.data.Dispose(); } } } diff --git a/crypto/src/cms/CMSEnvelopedDataGenerator.cs b/crypto/src/cms/CMSEnvelopedDataGenerator.cs
index 3b861cde5..5071af4ad 100644 --- a/crypto/src/cms/CMSEnvelopedDataGenerator.cs +++ b/crypto/src/cms/CMSEnvelopedDataGenerator.cs
@@ -80,7 +80,7 @@ namespace Org.BouncyCastle.Cms content.Write(cOut); - cOut.Close(); + cOut.Dispose(); encContent = new BerOctetString(bOut.ToArray()); } diff --git a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
index a63ea7b7f..cb5b246eb 100644 --- a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
@@ -255,27 +255,30 @@ namespace Org.BouncyCastle.Cms _out.Write(bytes, off, len); } - public override void Close() - { - _out.Close(); + protected override void Dispose(bool disposing) + { + if (disposing) + { + _out.Dispose(); - // TODO Parent context(s) should really be be closed explicitly + // TODO Parent context(s) should really be be closed explicitly - _eiGen.Close(); + _eiGen.Close(); - if (_outer.unprotectedAttributeGenerator != null) - { - Asn1.Cms.AttributeTable attrTable = _outer.unprotectedAttributeGenerator.GetAttributes(Platform.CreateHashtable()); + if (_outer.unprotectedAttributeGenerator != null) + { + Asn1.Cms.AttributeTable attrTable = _outer.unprotectedAttributeGenerator.GetAttributes(Platform.CreateHashtable()); - Asn1Set unprotectedAttrs = new BerSet(attrTable.ToAsn1EncodableVector()); + Asn1Set unprotectedAttrs = new BerSet(attrTable.ToAsn1EncodableVector()); - _envGen.AddObject(new DerTaggedObject(false, 1, unprotectedAttrs)); - } + _envGen.AddObject(new DerTaggedObject(false, 1, unprotectedAttrs)); + } - _envGen.Close(); - _cGen.Close(); - base.Close(); - } + _envGen.Close(); + _cGen.Close(); + } + base.Dispose(disposing); + } } } } diff --git a/crypto/src/cms/CMSProcessableInputStream.cs b/crypto/src/cms/CMSProcessableInputStream.cs
index 7fdd1dfef..0af6cbf79 100644 --- a/crypto/src/cms/CMSProcessableInputStream.cs +++ b/crypto/src/cms/CMSProcessableInputStream.cs
@@ -29,7 +29,7 @@ namespace Org.BouncyCastle.Cms CheckSingleUsage(); Streams.PipeAll(input, output); - input.Close(); + input.Dispose(); } [Obsolete] diff --git a/crypto/src/cms/CMSSignedDataGenerator.cs b/crypto/src/cms/CMSSignedDataGenerator.cs
index f31105c41..8b1debf92 100644 --- a/crypto/src/cms/CMSSignedDataGenerator.cs +++ b/crypto/src/cms/CMSSignedDataGenerator.cs
@@ -145,7 +145,7 @@ namespace Org.BouncyCastle.Cms content.Write(sigStr); } - sigStr.Close(); + sigStr.Dispose(); byte[] sigBytes = sig.GenerateSignature(); Asn1Set unsignedAttr = null; diff --git a/crypto/src/cms/CMSSignedDataParser.cs b/crypto/src/cms/CMSSignedDataParser.cs
index e5674a4cf..ec5a84fdf 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(); + contentOut.Dispose(); return outStr; } @@ -434,7 +434,7 @@ namespace Org.BouncyCastle.Cms gen.AddSigners(parser.GetSignerInfos()); - contentOut.Close(); + contentOut.Dispose(); return outStr; } diff --git a/crypto/src/cms/CMSSignedDataStreamGenerator.cs b/crypto/src/cms/CMSSignedDataStreamGenerator.cs
index 743e9c6c1..395a8ba98 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(); + signedOut.Dispose(); } // RFC3852, section 5.1: @@ -809,97 +809,100 @@ namespace Org.BouncyCastle.Cms _out.Write(bytes, off, len); } - public override void Close() - { - _out.Close(); + protected override void Dispose(bool disposing) + { + if (disposing) + { + _out.Dispose(); - // TODO Parent context(s) should really be be closed explicitly + // TODO Parent context(s) should really be be closed explicitly - _eiGen.Close(); + _eiGen.Close(); - outer._digests.Clear(); // clear the current preserved digest state + outer._digests.Clear(); // clear the current preserved digest state - if (outer._certs.Count > 0) - { - Asn1Set certs = CmsUtilities.CreateBerSetFromList(outer._certs); + if (outer._certs.Count > 0) + { + Asn1Set certs = CmsUtilities.CreateBerSetFromList(outer._certs); - WriteToGenerator(_sigGen, new BerTaggedObject(false, 0, certs)); - } + WriteToGenerator(_sigGen, new BerTaggedObject(false, 0, certs)); + } - if (outer._crls.Count > 0) - { - Asn1Set crls = CmsUtilities.CreateBerSetFromList(outer._crls); + if (outer._crls.Count > 0) + { + Asn1Set crls = CmsUtilities.CreateBerSetFromList(outer._crls); - WriteToGenerator(_sigGen, new BerTaggedObject(false, 1, crls)); - } + WriteToGenerator(_sigGen, new BerTaggedObject(false, 1, crls)); + } - // - // Calculate the digest hashes - // - foreach (DictionaryEntry de in outer._messageDigests) - { - outer._messageHashes.Add(de.Key, DigestUtilities.DoFinal((IDigest)de.Value)); - } + // + // Calculate the digest hashes + // + foreach (DictionaryEntry de in outer._messageDigests) + { + outer._messageHashes.Add(de.Key, DigestUtilities.DoFinal((IDigest)de.Value)); + } - // TODO If the digest OIDs for precalculated signers weren't mixed in with - // the others, we could fill in outer._digests here, instead of SignerInfoGenerator.Generate + // TODO If the digest OIDs for precalculated signers weren't mixed in with + // the others, we could fill in outer._digests here, instead of SignerInfoGenerator.Generate - // - // collect all the SignerInfo objects - // - Asn1EncodableVector signerInfos = new Asn1EncodableVector(); + // + // collect all the SignerInfo objects + // + Asn1EncodableVector signerInfos = new Asn1EncodableVector(); - // - // add the generated SignerInfo objects - // - { - foreach (DigestAndSignerInfoGeneratorHolder holder in outer._signerInfs) - { - AlgorithmIdentifier digestAlgorithm = holder.DigestAlgorithm; - - byte[] calculatedDigest = (byte[])outer._messageHashes[ - Helper.GetDigestAlgName(holder.digestOID)]; - outer._digests[holder.digestOID] = calculatedDigest.Clone(); + // + // add the generated SignerInfo objects + // + { + foreach (DigestAndSignerInfoGeneratorHolder holder in outer._signerInfs) + { + AlgorithmIdentifier digestAlgorithm = holder.DigestAlgorithm; - signerInfos.Add(holder.signerInf.Generate(_contentOID, digestAlgorithm, calculatedDigest)); - } - } + byte[] calculatedDigest = (byte[])outer._messageHashes[ + Helper.GetDigestAlgName(holder.digestOID)]; + outer._digests[holder.digestOID] = calculatedDigest.Clone(); - // - // add the precalculated SignerInfo objects. - // - { - foreach (SignerInformation signer in outer._signers) - { - // TODO Verify the content type and calculated digest match the precalculated SignerInfo -// if (!signer.ContentType.Equals(_contentOID)) -// { -// // TODO The precalculated content type did not match - error? -// } -// -// byte[] calculatedDigest = (byte[])outer._digests[signer.DigestAlgOid]; -// if (calculatedDigest == null) -// { -// // TODO We can't confirm this digest because we didn't calculate it - error? -// } -// else -// { -// if (!Arrays.AreEqual(signer.GetContentDigest(), calculatedDigest)) -// { -// // TODO The precalculated digest did not match - error? -// } -// } + signerInfos.Add(holder.signerInf.Generate(_contentOID, digestAlgorithm, calculatedDigest)); + } + } - signerInfos.Add(signer.ToSignerInfo()); - } - } + // + // add the precalculated SignerInfo objects. + // + { + foreach (SignerInformation signer in outer._signers) + { + // TODO Verify the content type and calculated digest match the precalculated SignerInfo + // if (!signer.ContentType.Equals(_contentOID)) + // { + // // TODO The precalculated content type did not match - error? + // } + // + // byte[] calculatedDigest = (byte[])outer._digests[signer.DigestAlgOid]; + // if (calculatedDigest == null) + // { + // // TODO We can't confirm this digest because we didn't calculate it - error? + // } + // else + // { + // if (!Arrays.AreEqual(signer.GetContentDigest(), calculatedDigest)) + // { + // // TODO The precalculated digest did not match - error? + // } + // } + + signerInfos.Add(signer.ToSignerInfo()); + } + } - WriteToGenerator(_sigGen, new DerSet(signerInfos)); + WriteToGenerator(_sigGen, new DerSet(signerInfos)); - _sigGen.Close(); - _sGen.Close(); - base.Close(); - } + _sigGen.Close(); + _sGen.Close(); + } + base.Dispose(disposing); + } private static void WriteToGenerator( Asn1Generator ag, diff --git a/crypto/src/cms/CMSTypedStream.cs b/crypto/src/cms/CMSTypedStream.cs
index 9cb314211..edb22dd3d 100644 --- a/crypto/src/cms/CMSTypedStream.cs +++ b/crypto/src/cms/CMSTypedStream.cs
@@ -53,7 +53,7 @@ namespace Org.BouncyCastle.Cms public void Drain() { Streams.Drain(_in); - _in.Close(); + _in.Dispose(); } private class FullReaderStream : FilterStream diff --git a/crypto/src/crypto/engines/NaccacheSternEngine.cs b/crypto/src/crypto/engines/NaccacheSternEngine.cs
index 9ca092351..486c8803e 100644 --- a/crypto/src/crypto/engines/NaccacheSternEngine.cs +++ b/crypto/src/crypto/engines/NaccacheSternEngine.cs
@@ -51,7 +51,8 @@ namespace Org.BouncyCastle.Crypto.Engines { if (debug) { - Console.WriteLine("Constructing lookup Array"); + + System.Diagnostics.Debug.WriteLine("Constructing lookup Array"); } NaccacheSternPrivateKeyParameters priv = (NaccacheSternPrivateKeyParameters)key; IList primes = priv.SmallPrimesList; @@ -66,7 +67,7 @@ namespace Org.BouncyCastle.Crypto.Engines if (debug) { - Console.WriteLine("Constructing lookup ArrayList for " + actualPrimeValue); + System.Diagnostics.Debug.WriteLine("Constructing lookup ArrayList for " + actualPrimeValue); } BigInteger accJ = BigInteger.Zero; @@ -158,7 +159,7 @@ namespace Org.BouncyCastle.Crypto.Engines if (debug) { - Console.WriteLine("input as BigInteger: " + input); + System.Diagnostics.Debug.WriteLine("input as BigInteger: " + input); } byte[] output; @@ -180,7 +181,7 @@ namespace Org.BouncyCastle.Crypto.Engines { if (debug) { - Console.WriteLine("Prime is " + primes[i] + ", lookup table has size " + al.Count); + System.Diagnostics.Debug.WriteLine("Prime is " + primes[i] + ", lookup table has size " + al.Count); } throw new InvalidCipherTextException("Error in lookup Array for " + ((BigInteger)primes[i]).IntValue @@ -194,14 +195,14 @@ namespace Org.BouncyCastle.Crypto.Engines { if (debug) { - Console.WriteLine("Actual prime is " + primes[i]); - Console.WriteLine("Decrypted value is " + exp); + System.Diagnostics.Debug.WriteLine("Actual prime is " + primes[i]); + System.Diagnostics.Debug.WriteLine("Decrypted value is " + exp); - Console.WriteLine("LookupList for " + primes[i] + " with size " + lookup[i].Count + System.Diagnostics.Debug.WriteLine("LookupList for " + primes[i] + " with size " + lookup[i].Count + " is: "); for (int j = 0; j < lookup[i].Count; j++) { - Console.WriteLine(lookup[i][j]); + System.Diagnostics.Debug.WriteLine(lookup[i][j]); } } throw new InvalidCipherTextException("Lookup failed"); @@ -258,7 +259,7 @@ namespace Org.BouncyCastle.Crypto.Engines Array.Copy(tmp, 0, output, output.Length - tmp.Length, tmp.Length); if (debug) { - Console.WriteLine("Encrypted value is: " + new BigInteger(output)); + System.Diagnostics.Debug.WriteLine("Encrypted value is: " + new BigInteger(output)); } return output; } @@ -304,9 +305,9 @@ namespace Org.BouncyCastle.Crypto.Engines m1m2Crypt = m1m2Crypt.Mod(key.Modulus); if (debug) { - Console.WriteLine("c(m1) as BigInteger:....... " + m1Crypt); - Console.WriteLine("c(m2) as BigInteger:....... " + m2Crypt); - Console.WriteLine("c(m1)*c(m2)%n = c(m1+m2)%n: " + m1m2Crypt); + System.Diagnostics.Debug.WriteLine("c(m1) as BigInteger:....... " + m1Crypt); + System.Diagnostics.Debug.WriteLine("c(m2) as BigInteger:....... " + m2Crypt); + System.Diagnostics.Debug.WriteLine("c(m1)*c(m2)%n = c(m1+m2)%n: " + m1m2Crypt); } //byte[] output = key.Modulus.ToByteArray(); @@ -334,7 +335,7 @@ namespace Org.BouncyCastle.Crypto.Engines { if (debug) { - Console.WriteLine(); + System.Diagnostics.Debug.WriteLine(""); } if (data.Length > GetInputBlockSize()) { @@ -342,9 +343,9 @@ namespace Org.BouncyCastle.Crypto.Engines int outBlocksize = GetOutputBlockSize(); if (debug) { - Console.WriteLine("Input blocksize is: " + inBlocksize + " bytes"); - Console.WriteLine("Output blocksize is: " + outBlocksize + " bytes"); - Console.WriteLine("Data has length:.... " + data.Length + " bytes"); + System.Diagnostics.Debug.WriteLine("Input blocksize is: " + inBlocksize + " bytes"); + System.Diagnostics.Debug.WriteLine("Output blocksize is: " + outBlocksize + " bytes"); + System.Diagnostics.Debug.WriteLine("Data has length:.... " + data.Length + " bytes"); } int datapos = 0; int retpos = 0; @@ -364,7 +365,7 @@ namespace Org.BouncyCastle.Crypto.Engines } if (debug) { - Console.WriteLine("new datapos is " + datapos); + System.Diagnostics.Debug.WriteLine("new datapos is " + datapos); } if (tmp != null) { @@ -375,7 +376,7 @@ namespace Org.BouncyCastle.Crypto.Engines { if (debug) { - Console.WriteLine("cipher returned null"); + System.Diagnostics.Debug.WriteLine("cipher returned null"); } throw new InvalidCipherTextException("cipher returned null"); } @@ -384,7 +385,7 @@ namespace Org.BouncyCastle.Crypto.Engines Array.Copy(retval, 0, ret, 0, retpos); if (debug) { - Console.WriteLine("returning " + ret.Length + " bytes"); + System.Diagnostics.Debug.WriteLine("returning " + ret.Length + " bytes"); } return ret; } @@ -392,7 +393,7 @@ namespace Org.BouncyCastle.Crypto.Engines { if (debug) { - Console.WriteLine("data size is less then input block size, processing directly"); + System.Diagnostics.Debug.WriteLine("data size is less then input block size, processing directly"); } return ProcessBlock(data, 0, data.Length); } diff --git a/crypto/src/crypto/generators/NaccacheSternKeyPairGenerator.cs b/crypto/src/crypto/generators/NaccacheSternKeyPairGenerator.cs
index 7011cf253..e69813f9e 100644 --- a/crypto/src/crypto/generators/NaccacheSternKeyPairGenerator.cs +++ b/crypto/src/crypto/generators/NaccacheSternKeyPairGenerator.cs
@@ -55,7 +55,7 @@ namespace Org.BouncyCastle.Crypto.Generators if (debug) { - Console.WriteLine("Fetching first " + param.CountSmallPrimes + " primes."); + System.Diagnostics.Debug.WriteLine("Fetching first " + param.CountSmallPrimes + " primes."); } IList smallPrimes = findFirstPrimes(param.CountSmallPrimes); @@ -94,7 +94,7 @@ namespace Org.BouncyCastle.Crypto.Generators long tries = 0; if (debug) { - Console.WriteLine("generating p and q"); + System.Diagnostics.Debug.WriteLine("generating p and q"); } BigInteger _2au = a.Multiply(u).ShiftLeft(1); @@ -126,7 +126,7 @@ namespace Org.BouncyCastle.Crypto.Generators if (!sigma.Gcd(_p.Multiply(_q)).Equals(BigInteger.One)) { - Console.WriteLine("sigma.gcd(_p.mult(_q)) != 1!\n _p: " + _p +"\n _q: "+ _q ); + System.Diagnostics.Debug.WriteLine("sigma.gcd(_p.mult(_q)) != 1!\n _p: " + _p + "\n _q: " + _q); continue; } @@ -134,7 +134,7 @@ namespace Org.BouncyCastle.Crypto.Generators { if (debug) { - Console.WriteLine("key size too small. Should be " + strength + " but is actually " + System.Diagnostics.Debug.WriteLine("key size too small. Should be " + strength + " but is actually " + p.Multiply(q).BitLength); } continue; @@ -144,7 +144,7 @@ namespace Org.BouncyCastle.Crypto.Generators if (debug) { - Console.WriteLine("needed " + tries + " tries to generate p and q."); + System.Diagnostics.Debug.WriteLine("needed " + tries + " tries to generate p and q."); } BigInteger n = p.Multiply(q); @@ -153,7 +153,7 @@ namespace Org.BouncyCastle.Crypto.Generators tries = 0; if (debug) { - Console.WriteLine("generating g"); + System.Diagnostics.Debug.WriteLine("generating g"); } for (;;) { @@ -193,7 +193,7 @@ namespace Org.BouncyCastle.Crypto.Generators { if (debug) { - Console.WriteLine("g has order phi(n)/" + smallPrimes[i] + "\n g: " + g); + System.Diagnostics.Debug.WriteLine("g has order phi(n)/" + smallPrimes[i] + "\n g: " + g); } divisible = true; break; @@ -212,7 +212,7 @@ namespace Org.BouncyCastle.Crypto.Generators { if (debug) { - Console.WriteLine("g has order phi(n)/4\n g:" + g); + System.Diagnostics.Debug.WriteLine("g has order phi(n)/4\n g:" + g); } continue; } @@ -221,7 +221,7 @@ namespace Org.BouncyCastle.Crypto.Generators { if (debug) { - Console.WriteLine("g has order phi(n)/p'\n g: " + g); + System.Diagnostics.Debug.WriteLine("g has order phi(n)/p'\n g: " + g); } continue; } @@ -229,7 +229,7 @@ namespace Org.BouncyCastle.Crypto.Generators { if (debug) { - Console.WriteLine("g has order phi(n)/q'\n g: " + g); + System.Diagnostics.Debug.WriteLine("g has order phi(n)/q'\n g: " + g); } continue; } @@ -237,7 +237,7 @@ namespace Org.BouncyCastle.Crypto.Generators { if (debug) { - Console.WriteLine("g has order phi(n)/a\n g: " + g); + System.Diagnostics.Debug.WriteLine("g has order phi(n)/a\n g: " + g); } continue; } @@ -245,7 +245,7 @@ namespace Org.BouncyCastle.Crypto.Generators { if (debug) { - Console.WriteLine("g has order phi(n)/b\n g: " + g); + System.Diagnostics.Debug.WriteLine("g has order phi(n)/b\n g: " + g); } continue; } @@ -253,21 +253,21 @@ namespace Org.BouncyCastle.Crypto.Generators } if (debug) { - Console.WriteLine("needed " + tries + " tries to generate g"); - Console.WriteLine(); - Console.WriteLine("found new NaccacheStern cipher variables:"); - Console.WriteLine("smallPrimes: " + CollectionUtilities.ToString(smallPrimes)); - Console.WriteLine("sigma:...... " + sigma + " (" + sigma.BitLength + " bits)"); - Console.WriteLine("a:.......... " + a); - Console.WriteLine("b:.......... " + b); - Console.WriteLine("p':......... " + _p); - Console.WriteLine("q':......... " + _q); - Console.WriteLine("p:.......... " + p); - Console.WriteLine("q:.......... " + q); - Console.WriteLine("n:.......... " + n); - Console.WriteLine("phi(n):..... " + phi_n); - Console.WriteLine("g:.......... " + g); - Console.WriteLine(); + System.Diagnostics.Debug.WriteLine("needed " + tries + " tries to generate g"); + System.Diagnostics.Debug.WriteLine(""); + System.Diagnostics.Debug.WriteLine("found new NaccacheStern cipher variables:"); + System.Diagnostics.Debug.WriteLine("smallPrimes: " + CollectionUtilities.ToString(smallPrimes)); + System.Diagnostics.Debug.WriteLine("sigma:...... " + sigma + " (" + sigma.BitLength + " bits)"); + System.Diagnostics.Debug.WriteLine("a:.......... " + a); + System.Diagnostics.Debug.WriteLine("b:.......... " + b); + System.Diagnostics.Debug.WriteLine("p':......... " + _p); + System.Diagnostics.Debug.WriteLine("q':......... " + _q); + System.Diagnostics.Debug.WriteLine("p:.......... " + p); + System.Diagnostics.Debug.WriteLine("q:.......... " + q); + System.Diagnostics.Debug.WriteLine("n:.......... " + n); + System.Diagnostics.Debug.WriteLine("phi(n):..... " + phi_n); + System.Diagnostics.Debug.WriteLine("g:.......... " + g); + System.Diagnostics.Debug.WriteLine(""); } return new AsymmetricCipherKeyPair(new NaccacheSternKeyParameters(false, g, n, sigma.BitLength), diff --git a/crypto/src/crypto/io/CipherStream.cs b/crypto/src/crypto/io/CipherStream.cs
index b6920854d..f2083e878 100644 --- a/crypto/src/crypto/io/CipherStream.cs +++ b/crypto/src/crypto/io/CipherStream.cs
@@ -201,15 +201,19 @@ namespace Org.BouncyCastle.Crypto.IO set { throw new NotSupportedException(); } } - public override void Close() + protected override void Dispose(bool disposing) { - if (outCipher != null) - { - byte[] data = outCipher.DoFinal(); - stream.Write(data, 0, data.Length); - stream.Flush(); - } - stream.Close(); + if (disposing) + { + if (outCipher != null) + { + byte[] data = outCipher.DoFinal(); + stream.Write(data, 0, data.Length); + stream.Flush(); + } + stream.Dispose(); + } + base.Dispose(disposing); } public override void Flush() diff --git a/crypto/src/crypto/io/DigestStream.cs b/crypto/src/crypto/io/DigestStream.cs
index c819a409a..b0a69f03e 100644 --- a/crypto/src/crypto/io/DigestStream.cs +++ b/crypto/src/crypto/io/DigestStream.cs
@@ -110,10 +110,14 @@ namespace Org.BouncyCastle.Crypto.IO set { stream.Position = value; } } - public override void Close() - { - stream.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + stream.Dispose(); + } + base.Dispose(disposing); + } public override void Flush() { diff --git a/crypto/src/crypto/io/MacStream.cs b/crypto/src/crypto/io/MacStream.cs
index 51cf1832e..c7feabcae 100644 --- a/crypto/src/crypto/io/MacStream.cs +++ b/crypto/src/crypto/io/MacStream.cs
@@ -109,10 +109,14 @@ namespace Org.BouncyCastle.Crypto.IO set { stream.Position = value; } } - public override void Close() - { - stream.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + stream.Dispose(); + } + base.Dispose(disposing); + } public override void Flush() { diff --git a/crypto/src/crypto/io/SignerStream.cs b/crypto/src/crypto/io/SignerStream.cs
index 49dfb38c6..2a609f6ee 100644 --- a/crypto/src/crypto/io/SignerStream.cs +++ b/crypto/src/crypto/io/SignerStream.cs
@@ -110,10 +110,14 @@ namespace Org.BouncyCastle.Crypto.IO set { stream.Position = value; } } - public override void Close() - { - stream.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + stream.Dispose(); + } + base.Dispose(disposing); + } public override void Flush() { diff --git a/crypto/src/crypto/modes/CcmBlockCipher.cs b/crypto/src/crypto/modes/CcmBlockCipher.cs
index 653d75cb9..d58a2cb20 100644 --- a/crypto/src/crypto/modes/CcmBlockCipher.cs +++ b/crypto/src/crypto/modes/CcmBlockCipher.cs
@@ -137,7 +137,7 @@ namespace Org.BouncyCastle.Crypto.Modes byte[] outBytes, int outOff) { - byte[] enc = ProcessPacket(data.GetBuffer(), 0, (int)data.Position); + byte[] enc = ProcessPacket(data.ToArray(), 0, (int)data.Position); Array.Copy(enc, 0, outBytes, outOff, enc.Length); @@ -349,7 +349,7 @@ namespace Org.BouncyCastle.Crypto.Modes } if (associatedText.Position > 0) { - cMac.BlockUpdate(associatedText.GetBuffer(), 0, (int)associatedText.Position); + cMac.BlockUpdate(associatedText.ToArray(), 0, (int)associatedText.Position); } extra = (extra + textLength) % 16; diff --git a/crypto/src/crypto/parameters/SkeinParameters.cs b/crypto/src/crypto/parameters/SkeinParameters.cs
index a4e3e8e2a..f1f5f33ec 100644 --- a/crypto/src/crypto/parameters/SkeinParameters.cs +++ b/crypto/src/crypto/parameters/SkeinParameters.cs
@@ -239,7 +239,7 @@ namespace Org.BouncyCastle.Crypto.Parameters outBytes.Write(emailAddress); outBytes.Write(" "); outBytes.Write(distinguisher); - outBytes.Close(); + outBytes.Dispose(); 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..b51121121 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(); + this.Dispose(); } } } diff --git a/crypto/src/crypto/tls/HeartbeatMessage.cs b/crypto/src/crypto/tls/HeartbeatMessage.cs
index f64a7baa4..daf366ed1 100644 --- a/crypto/src/crypto/tls/HeartbeatMessage.cs +++ b/crypto/src/crypto/tls/HeartbeatMessage.cs
@@ -95,7 +95,7 @@ namespace Org.BouncyCastle.Crypto.Tls int minimumCount = payloadLength + 16; if (Length < minimumCount) return null; - return Arrays.CopyOf(GetBuffer(), payloadLength); + return Arrays.CopyOf(ToArray(), payloadLength); } } } diff --git a/crypto/src/crypto/tls/RecordStream.cs b/crypto/src/crypto/tls/RecordStream.cs
index db5b158bc..e5d0febeb 100644 --- a/crypto/src/crypto/tls/RecordStream.cs +++ b/crypto/src/crypto/tls/RecordStream.cs
@@ -282,7 +282,7 @@ namespace Org.BouncyCastle.Crypto.Tls { try { - mInput.Close(); + mInput.Dispose(); } catch (IOException) { @@ -290,7 +290,7 @@ namespace Org.BouncyCastle.Crypto.Tls try { - mOutput.Close(); + mOutput.Dispose(); } catch (IOException) { diff --git a/crypto/src/crypto/tls/TlsProtocol.cs b/crypto/src/crypto/tls/TlsProtocol.cs
index 8ba156952..11be32256 100644 --- a/crypto/src/crypto/tls/TlsProtocol.cs +++ b/crypto/src/crypto/tls/TlsProtocol.cs
@@ -1094,8 +1094,8 @@ namespace Org.BouncyCastle.Crypto.Tls TlsUtilities.CheckUint24(length); this.Position = 1; TlsUtilities.WriteUint24((int)length, this); - protocol.WriteHandshakeMessage(GetBuffer(), 0, (int)Length); - this.Close(); + protocol.WriteHandshakeMessage(ToArray(), 0, (int)Length); + this.Dispose(); } } } diff --git a/crypto/src/crypto/tls/TlsStream.cs b/crypto/src/crypto/tls/TlsStream.cs
index 7ff7184e3..f78ba0344 100644 --- a/crypto/src/crypto/tls/TlsStream.cs +++ b/crypto/src/crypto/tls/TlsStream.cs
@@ -28,9 +28,13 @@ namespace Org.BouncyCastle.Crypto.Tls get { return !handler.IsClosed; } } - public override void Close() + protected override void Dispose(bool disposing) { - handler.Close(); + if (disposing) + { + handler.Close(); + } + base.Dispose(disposing); } public override void Flush() diff --git a/crypto/src/openpgp/PgpCompressedDataGenerator.cs b/crypto/src/openpgp/PgpCompressedDataGenerator.cs
index 7f4ec8e53..f5626ee1a 100644 --- a/crypto/src/openpgp/PgpCompressedDataGenerator.cs +++ b/crypto/src/openpgp/PgpCompressedDataGenerator.cs
@@ -155,7 +155,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { if (dOut != pkOut) { - dOut.Close(); + dOut.Dispose(); dOut.Flush(); } @@ -174,10 +174,14 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { } - public override void Close() - { - Finish(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + Finish(); + } + base.Dispose(disposing); + } } private class SafeZOutputStream : ZOutputStream diff --git a/crypto/src/openpgp/WrappedGeneratorStream.cs b/crypto/src/openpgp/WrappedGeneratorStream.cs
index 6fc7329af..9fe2e33d7 100644 --- a/crypto/src/openpgp/WrappedGeneratorStream.cs +++ b/crypto/src/openpgp/WrappedGeneratorStream.cs
@@ -17,9 +17,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp this.gen = gen; } - public override void Close() - { - gen.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + gen.Close(); + } + base.Dispose(disposing); + } } } diff --git a/crypto/src/pkcs/Pkcs12Store.cs b/crypto/src/pkcs/Pkcs12Store.cs
index 40364eec7..7e9976c9f 100644 --- a/crypto/src/pkcs/Pkcs12Store.cs +++ b/crypto/src/pkcs/Pkcs12Store.cs
@@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Diagnostics; using System.IO; using System.Text; @@ -258,8 +259,8 @@ namespace Org.BouncyCastle.Pkcs } else { - Console.WriteLine("extra " + b.BagID); - Console.WriteLine("extra " + Asn1Dump.DumpAsString(b)); + Debug.WriteLine("extra " + b.BagID); + Debug.WriteLine("extra " + Asn1Dump.DumpAsString(b)); } } } @@ -416,15 +417,15 @@ namespace Org.BouncyCastle.Pkcs } else { - Console.WriteLine("extra " + b.BagID); - Console.WriteLine("extra " + Asn1Dump.DumpAsString(b)); + Debug.WriteLine("extra " + b.BagID); + Debug.WriteLine("extra " + Asn1Dump.DumpAsString(b)); } } } else { - Console.WriteLine("extra " + oid); - Console.WriteLine("extra " + Asn1Dump.DumpAsString(ci.Content)); + Debug.WriteLine("extra " + oid); + Debug.WriteLine("extra " + Asn1Dump.DumpAsString(ci.Content)); } } } diff --git a/crypto/src/pkix/PkixCertPath.cs b/crypto/src/pkix/PkixCertPath.cs
index e3d3ea7fe..aca6b73a1 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(); + pWrt.Writer.Dispose(); } catch (Exception) { diff --git a/crypto/src/util/Enums.cs b/crypto/src/util/Enums.cs
index 8bd9c4053..d943acdd3 100644 --- a/crypto/src/util/Enums.cs +++ b/crypto/src/util/Enums.cs
@@ -42,7 +42,7 @@ namespace Org.BouncyCastle.Utilities if (!enumType.IsEnum) throw new ArgumentException("Not an enumeration type", "enumType"); -#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT +#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT && !PCL IList result = Platform.CreateArrayList(); FieldInfo[] fields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo field in fields) diff --git a/crypto/src/util/io/BaseInputStream.cs b/crypto/src/util/io/BaseInputStream.cs
index 3ff4a1957..2407bbabe 100644 --- a/crypto/src/util/io/BaseInputStream.cs +++ b/crypto/src/util/io/BaseInputStream.cs
@@ -11,8 +11,17 @@ 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() {} + protected override void Dispose(bool disposing) + { + if (disposing) + { + closed = true; + } + + base.Dispose(disposing); + } + + 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..56ce847e0 100644 --- a/crypto/src/util/io/BaseOutputStream.cs +++ b/crypto/src/util/io/BaseOutputStream.cs
@@ -11,7 +11,14 @@ 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; } + protected override void Dispose(bool disposing) + { + if (disposing) + { + closed = true; + } + base.Dispose(disposing); + } 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/TeeInputStream.cs b/crypto/src/util/io/TeeInputStream.cs
index 373df4502..aeed3bae6 100644 --- a/crypto/src/util/io/TeeInputStream.cs +++ b/crypto/src/util/io/TeeInputStream.cs
@@ -18,11 +18,15 @@ namespace Org.BouncyCastle.Utilities.IO this.tee = tee; } - public override void Close() - { - input.Close(); - tee.Close(); - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + input.Dispose(); + tee.Dispose(); + } + base.Dispose(disposing); + } 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 fe3a7586a..cebca89fe 100644 --- a/crypto/src/util/io/TeeOutputStream.cs +++ b/crypto/src/util/io/TeeOutputStream.cs
@@ -18,12 +18,16 @@ namespace Org.BouncyCastle.Utilities.IO this.tee = tee; } - public override void Close() - { - output.Close(); - tee.Close(); - } - + protected override void Dispose(bool disposing) + { + if (disposing) + { + output.Dispose(); + tee.Dispose(); + } + base.Dispose(disposing); + } + public override void Write(byte[] buffer, int offset, int count) { output.Write(buffer, offset, count); diff --git a/crypto/src/util/zlib/ZDeflaterOutputStream.cs b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
index 1d88847bd..544ba8601 100644 --- a/crypto/src/util/zlib/ZDeflaterOutputStream.cs +++ b/crypto/src/util/zlib/ZDeflaterOutputStream.cs
@@ -135,17 +135,24 @@ namespace Org.BouncyCastle.Utilities.Zlib { z.free(); z=null; } - - public override void Close() { - try{ - try{Finish();} - catch (IOException) {} - } - finally{ - End(); - outp.Close(); - outp=null; + + protected override void Dispose(bool disposing) + { + if (disposing) + { + try + { + try { Finish(); } + catch (IOException) { } + } + finally + { + End(); + outp.Dispose(); + outp = null; + } } + base.Dispose(disposing); } } } diff --git a/crypto/src/util/zlib/ZInflaterInputStream.cs b/crypto/src/util/zlib/ZInflaterInputStream.cs
index 5a3ff5aa6..9e82954b9 100644 --- a/crypto/src/util/zlib/ZInflaterInputStream.cs +++ b/crypto/src/util/zlib/ZInflaterInputStream.cs
@@ -114,8 +114,13 @@ namespace Org.BouncyCastle.Utilities.Zlib { public override void WriteByte(byte b) { } - public override void Close() { - inp.Close(); + protected override void Dispose(bool disposing) + { + if (disposing) + { + inp.Dispose(); + } + base.Dispose(disposing); } public override int ReadByte() { diff --git a/crypto/src/util/zlib/ZInputStream.cs b/crypto/src/util/zlib/ZInputStream.cs
index d1e1ba160..671cf68b0 100644 --- a/crypto/src/util/zlib/ZInputStream.cs +++ b/crypto/src/util/zlib/ZInputStream.cs
@@ -93,14 +93,18 @@ 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 (!closed) - { - closed = true; - input.Close(); - } - } + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (!closed) + { + closed = true; + input.Dispose(); + } + } + base.Dispose(disposing); + } public sealed override void Flush() {} diff --git a/crypto/src/util/zlib/ZOutputStream.cs b/crypto/src/util/zlib/ZOutputStream.cs
index 1d2ead7b3..2cef06397 100644 --- a/crypto/src/util/zlib/ZOutputStream.cs +++ b/crypto/src/util/zlib/ZOutputStream.cs
@@ -95,31 +95,35 @@ namespace Org.BouncyCastle.Utilities.Zlib public sealed override bool CanSeek { get { return false; } } public sealed override bool CanWrite { get { return !closed; } } - public override void Close() - { - if (this.closed) - return; - - try - { - try - { - Finish(); - } - catch (IOException) - { - // Ignore - } - } - finally - { - this.closed = true; - End(); - output.Close(); - output = null; - } - } - + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (this.closed) + return; + + try + { + try + { + Finish(); + } + catch (IOException) + { + // Ignore + } + } + finally + { + this.closed = true; + End(); + output.Dispose(); + output = null; + } + } + base.Dispose(disposing); + } + public virtual void End() { if (z == null)