summary refs log tree commit diff
path: root/crypto/src/cms/CMSCompressedDataGenerator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/cms/CMSCompressedDataGenerator.cs')
-rw-r--r--crypto/src/cms/CMSCompressedDataGenerator.cs17
1 files changed, 9 insertions, 8 deletions
diff --git a/crypto/src/cms/CMSCompressedDataGenerator.cs b/crypto/src/cms/CMSCompressedDataGenerator.cs
index bea04752a..70515e8d3 100644
--- a/crypto/src/cms/CMSCompressedDataGenerator.cs
+++ b/crypto/src/cms/CMSCompressedDataGenerator.cs
@@ -5,7 +5,6 @@ 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
 {
@@ -22,32 +21,34 @@ namespace Org.BouncyCastle.Cms
     */
     public class CmsCompressedDataGenerator
     {
-        public const string ZLib = "1.2.840.113549.1.9.16.3.8";
+        public static readonly string ZLib = CmsObjectIdentifiers.ZlibCompress.Id;
 
-		public CmsCompressedDataGenerator()
+        public CmsCompressedDataGenerator()
         {
         }
 
 		/**
         * Generate an object that contains an CMS Compressed Data
         */
-        public CmsCompressedData Generate(
-            CmsProcessable	content,
-            string			compressionOid)
+        public CmsCompressedData Generate(CmsProcessable content, string compressionOid)
         {
+            if (ZLib != compressionOid)
+                throw new ArgumentException("Unsupported compression algorithm: " + compressionOid,
+                    nameof(compressionOid));
+
             AlgorithmIdentifier comAlgId;
             Asn1OctetString comOcts;
 
             try
             {
                 MemoryStream bOut = new MemoryStream();
-                ZOutputStream zOut = new ZOutputStream(bOut, JZlib.Z_DEFAULT_COMPRESSION);
+                Stream zOut = Utilities.IO.Compression.ZLib.CompressOutput(bOut, -1);
 
 				content.Write(zOut);
 
                 Platform.Dispose(zOut);
 
-                comAlgId = new AlgorithmIdentifier(new DerObjectIdentifier(compressionOid));
+                comAlgId = new AlgorithmIdentifier(CmsObjectIdentifiers.ZlibCompress);
 				comOcts = new BerOctetString(bOut.ToArray());
             }
             catch (IOException e)