summary refs log tree commit diff
path: root/crypto/src/cms/CMSSignedDataStreamGenerator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/cms/CMSSignedDataStreamGenerator.cs')
-rw-r--r--crypto/src/cms/CMSSignedDataStreamGenerator.cs155
1 files changed, 79 insertions, 76 deletions
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,