summary refs log tree commit diff
path: root/crypto/src/cms
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-24 15:49:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-24 15:49:27 +0700
commitbe97c80fdecadac37413a6a6a8de417e0332f6bf (patch)
treedef3bf31b937a4e59458574f6441036ffdf61616 /crypto/src/cms
parentUse correct OID (diff)
downloadBouncyCastle.NET-ed25519-be97c80fdecadac37413a6a6a8de417e0332f6bf.tar.xz
Use platform compression where available
- Move Bzip2 code into Utilities
Diffstat (limited to 'crypto/src/cms')
-rw-r--r--crypto/src/cms/CMSCompressedData.cs8
-rw-r--r--crypto/src/cms/CMSCompressedDataGenerator.cs10
-rw-r--r--crypto/src/cms/CMSCompressedDataParser.cs5
-rw-r--r--crypto/src/cms/CMSCompressedDataStreamGenerator.cs12
4 files changed, 19 insertions, 16 deletions
diff --git a/crypto/src/cms/CMSCompressedData.cs b/crypto/src/cms/CMSCompressedData.cs
index 21651f041..5f8165005 100644
--- a/crypto/src/cms/CMSCompressedData.cs
+++ b/crypto/src/cms/CMSCompressedData.cs
@@ -1,10 +1,9 @@
-using System;
 using System.IO;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
 using Org.BouncyCastle.Utilities;
-using Org.BouncyCastle.Utilities.Zlib;
+using Org.BouncyCastle.Utilities.IO.Compression;
 
 namespace Org.BouncyCastle.Cms
 {
@@ -45,7 +44,7 @@ namespace Org.BouncyCastle.Cms
             ContentInfo content = comData.EncapContentInfo;
 
 			Asn1OctetString bytes = (Asn1OctetString) content.Content;
-			ZInputStream zIn = new ZInputStream(bytes.GetOctetStream());
+			Stream zIn = ZLib.DecompressInput(bytes.GetOctetStream());
 
 			try
 			{
@@ -76,8 +75,7 @@ namespace Org.BouncyCastle.Cms
 			ContentInfo     content = comData.EncapContentInfo;
 
 			Asn1OctetString bytes = (Asn1OctetString)content.Content;
-
-			ZInputStream zIn = new ZInputStream(new MemoryStream(bytes.GetOctets(), false));
+            Stream zIn = ZLib.DecompressInput(bytes.GetOctetStream());
 
 			try
 			{
diff --git a/crypto/src/cms/CMSCompressedDataGenerator.cs b/crypto/src/cms/CMSCompressedDataGenerator.cs
index bea04752a..872c4a144 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,9 +21,12 @@ namespace Org.BouncyCastle.Cms
     */
     public class CmsCompressedDataGenerator
     {
-        public const string ZLib = "1.2.840.113549.1.9.16.3.8";
+        public const string ZLibOid = "1.2.840.113549.1.9.16.3.8";
 
-		public CmsCompressedDataGenerator()
+        [Obsolete("Use 'ZLibOid' instead")]
+        public const string ZLib = ZLibOid;
+
+        public CmsCompressedDataGenerator()
         {
         }
 
@@ -41,7 +43,7 @@ namespace Org.BouncyCastle.Cms
             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);
 
diff --git a/crypto/src/cms/CMSCompressedDataParser.cs b/crypto/src/cms/CMSCompressedDataParser.cs
index b107ff608..38ff88968 100644
--- a/crypto/src/cms/CMSCompressedDataParser.cs
+++ b/crypto/src/cms/CMSCompressedDataParser.cs
@@ -3,7 +3,7 @@ using System.IO;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
-using Org.BouncyCastle.Utilities.Zlib;
+using Org.BouncyCastle.Utilities.IO.Compression;
 
 namespace Org.BouncyCastle.Cms
 {
@@ -44,8 +44,9 @@ namespace Org.BouncyCastle.Cms
                 ContentInfoParser content = comData.GetEncapContentInfo();
 
                 Asn1OctetStringParser bytes = (Asn1OctetStringParser)content.GetContent(Asn1Tags.OctetString);
+                Stream zIn = ZLib.DecompressInput(bytes.GetOctetStream());
 
-                return new CmsTypedStream(content.ContentType.ToString(), new ZInputStream(bytes.GetOctetStream()));
+                return new CmsTypedStream(content.ContentType.ToString(), zIn);
             }
             catch (IOException e)
             {
diff --git a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
index 9a9c29b01..855367320 100644
--- a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs
@@ -6,7 +6,6 @@ using Org.BouncyCastle.Asn1.Cms;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Utilities;
 using Org.BouncyCastle.Utilities.IO;
-using Org.BouncyCastle.Utilities.Zlib;
 
 namespace Org.BouncyCastle.Cms
 {
@@ -27,7 +26,10 @@ namespace Org.BouncyCastle.Cms
 	*/
 	public class CmsCompressedDataStreamGenerator
 	{
-		public const string ZLib = "1.2.840.113549.1.9.16.3.8";
+        public const string ZLibOid = "1.2.840.113549.1.9.16.3.8";
+
+        [Obsolete("Use 'ZLibOid' instead")]
+        public const string ZLib = ZLibOid;
 
 		private int _bufferSize;
 		
@@ -88,19 +90,19 @@ namespace Org.BouncyCastle.Cms
 				eiGen.GetRawOutputStream(), 0, true, _bufferSize);
 
 			return new CmsCompressedOutputStream(
-				new ZOutputStream(octetStream, JZlib.Z_DEFAULT_COMPRESSION), sGen, cGen, eiGen);
+				Utilities.IO.Compression.ZLib.CompressOutput(octetStream, -1), sGen, cGen, eiGen);
 		}
 
 		private class CmsCompressedOutputStream
 			: BaseOutputStream
 		{
-			private ZOutputStream _out;
+			private Stream _out;
 			private BerSequenceGenerator _sGen;
 			private BerSequenceGenerator _cGen;
 			private BerSequenceGenerator _eiGen;
 
 			internal CmsCompressedOutputStream(
-				ZOutputStream			outStream,
+				Stream					outStream,
 				BerSequenceGenerator	sGen,
 				BerSequenceGenerator	cGen,
 				BerSequenceGenerator	eiGen)