summary refs log tree commit diff
path: root/crypto/src/openpgp
diff options
context:
space:
mode:
authorDavid Hook <david.hook@keyfactor.com>2022-10-29 18:56:29 +1100
committerDavid Hook <david.hook@keyfactor.com>2022-10-29 18:56:29 +1100
commit590610a1faf81601756bfc683154446802157c86 (patch)
tree871ef215c63025dfea08a4cdd99120ad8a07fa45 /crypto/src/openpgp
parentMerge remote-tracking branch 'refs/remotes/origin/master' (diff)
parentRelease preparations (diff)
downloadBouncyCastle.NET-ed25519-590610a1faf81601756bfc683154446802157c86.tar.xz
resolve conflicts
Diffstat (limited to 'crypto/src/openpgp')
-rw-r--r--crypto/src/openpgp/PgpCompressedData.cs23
-rw-r--r--crypto/src/openpgp/PgpCompressedDataGenerator.cs58
-rw-r--r--crypto/src/openpgp/PgpEncryptedDataGenerator.cs41
3 files changed, 52 insertions, 70 deletions
diff --git a/crypto/src/openpgp/PgpCompressedData.cs b/crypto/src/openpgp/PgpCompressedData.cs
index fc7d200d0..346b0b1a1 100644
--- a/crypto/src/openpgp/PgpCompressedData.cs
+++ b/crypto/src/openpgp/PgpCompressedData.cs
@@ -1,7 +1,6 @@
 using System.IO;
 
-using Org.BouncyCastle.Bzip2;
-using Org.BouncyCastle.Utilities.Zlib;
+using Org.BouncyCastle.Utilities.IO.Compression;
 
 namespace Org.BouncyCastle.Bcpg.OpenPgp
 {
@@ -38,16 +37,16 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
         {
             switch (Algorithm)
             {
-				case CompressionAlgorithmTag.Uncompressed:
-					return GetInputStream();
-				case CompressionAlgorithmTag.Zip:
-					return new ZInputStream(GetInputStream(), true);
-                case CompressionAlgorithmTag.ZLib:
-					return new ZInputStream(GetInputStream());
-				case CompressionAlgorithmTag.BZip2:
-					return new CBZip2InputStream(GetInputStream());
-                default:
-                    throw new PgpException("can't recognise compression algorithm: " + Algorithm);
+			case CompressionAlgorithmTag.Uncompressed:
+				return GetInputStream();
+			case CompressionAlgorithmTag.Zip:
+                return Zip.DecompressInput(GetInputStream());
+            case CompressionAlgorithmTag.ZLib:
+				return ZLib.DecompressInput(GetInputStream());
+			case CompressionAlgorithmTag.BZip2:
+                return Bzip2.DecompressInput(GetInputStream());
+            default:
+                throw new PgpException("can't recognise compression algorithm: " + Algorithm);
             }
         }
     }
diff --git a/crypto/src/openpgp/PgpCompressedDataGenerator.cs b/crypto/src/openpgp/PgpCompressedDataGenerator.cs
index 791aac0bf..d13d7402b 100644
--- a/crypto/src/openpgp/PgpCompressedDataGenerator.cs
+++ b/crypto/src/openpgp/PgpCompressedDataGenerator.cs
@@ -1,8 +1,8 @@
 using System;
 using System.IO;
 
-using Org.BouncyCastle.Bzip2;
 using Org.BouncyCastle.Utilities;
+using Org.BouncyCastle.Utilities.IO.Compression;
 using Org.BouncyCastle.Utilities.Zlib;
 
 namespace Org.BouncyCastle.Bcpg.OpenPgp
@@ -131,21 +131,21 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 
 			switch (algorithm)
 			{
-				case CompressionAlgorithmTag.Uncompressed:
-					dOut = pkOut;
-					break;
-				case CompressionAlgorithmTag.Zip:
-					dOut = new SafeZOutputStream(pkOut, compression, true);
-					break;
-				case CompressionAlgorithmTag.ZLib:
-					dOut = new SafeZOutputStream(pkOut, compression, false);
-					break;
-				case CompressionAlgorithmTag.BZip2:
-					dOut = new SafeCBZip2OutputStream(pkOut);
-					break;
-				default:
-					// Constructor should guard against this possibility
-					throw new InvalidOperationException();
+			case CompressionAlgorithmTag.Uncompressed:
+				dOut = pkOut;
+				break;
+			case CompressionAlgorithmTag.Zip:
+                dOut = Zip.CompressOutput(pkOut, compression, true);
+                break;
+			case CompressionAlgorithmTag.ZLib:
+				dOut = ZLib.CompressOutput(pkOut, compression, true);
+				break;
+			case CompressionAlgorithmTag.BZip2:
+				dOut = Bzip2.CompressOutput(pkOut, true);
+				break;
+			default:
+				// Constructor should guard against this possibility
+				throw new InvalidOperationException();
 			}
 		}
 
@@ -165,31 +165,5 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 				pkOut = null;
 			}
 		}
-
-		private class SafeCBZip2OutputStream : CBZip2OutputStream
-		{
-			public SafeCBZip2OutputStream(Stream output)
-				: base(output)
-			{
-			}
-
-            protected override void Dispose(bool disposing)
-            {
-                Detach(disposing);
-            }
-		}
-
-		private class SafeZOutputStream : ZOutputStream
-		{
-			public SafeZOutputStream(Stream output, int level, bool nowrap)
-				: base(output, level, nowrap)
-			{
-			}
-
-            protected override void Dispose(bool disposing)
-            {
-				Detach(disposing);
-            }
-		}
 	}
 }
diff --git a/crypto/src/openpgp/PgpEncryptedDataGenerator.cs b/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
index a86dce42d..589895522 100644
--- a/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
+++ b/crypto/src/openpgp/PgpEncryptedDataGenerator.cs
@@ -219,7 +219,7 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 			SymmetricKeyAlgorithmTag encAlgorithm)
 		{
 			this.defAlgorithm = encAlgorithm;
-			this.rand = new SecureRandom();
+            this.rand = CryptoServicesRegistrar.GetSecureRandom();
 		}
 
 		public PgpEncryptedDataGenerator(
@@ -228,42 +228,51 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp
 		{
 			this.defAlgorithm = encAlgorithm;
 			this.withIntegrityPacket = withIntegrityPacket;
-			this.rand = new SecureRandom();
-		}
+            this.rand = CryptoServicesRegistrar.GetSecureRandom();
+        }
 
-		/// <summary>Existing SecureRandom constructor.</summary>
-		/// <param name="encAlgorithm">The symmetric algorithm to use.</param>
-		/// <param name="rand">Source of randomness.</param>
+        /// <summary>Existing SecureRandom constructor.</summary>
+        /// <param name="encAlgorithm">The symmetric algorithm to use.</param>
+        /// <param name="random">Source of randomness.</param>
         public PgpEncryptedDataGenerator(
             SymmetricKeyAlgorithmTag	encAlgorithm,
-            SecureRandom				rand)
+            SecureRandom				random)
         {
+            if (random == null)
+                throw new ArgumentNullException(nameof(random));
+
             this.defAlgorithm = encAlgorithm;
-            this.rand = rand;
+            this.rand = random;
         }
 
 		/// <summary>Creates a cipher stream which will have an integrity packet associated with it.</summary>
         public PgpEncryptedDataGenerator(
             SymmetricKeyAlgorithmTag	encAlgorithm,
             bool						withIntegrityPacket,
-            SecureRandom				rand)
+            SecureRandom				random)
         {
+            if (random == null)
+                throw new ArgumentNullException(nameof(random));
+
             this.defAlgorithm = encAlgorithm;
-            this.rand = rand;
+            this.rand = random;
             this.withIntegrityPacket = withIntegrityPacket;
         }
 
-		/// <summary>Base constructor.</summary>
-		/// <param name="encAlgorithm">The symmetric algorithm to use.</param>
-		/// <param name="rand">Source of randomness.</param>
-		/// <param name="oldFormat">PGP 2.6.x compatibility required.</param>
+        /// <summary>Base constructor.</summary>
+        /// <param name="encAlgorithm">The symmetric algorithm to use.</param>
+        /// <param name="random">Source of randomness.</param>
+        /// <param name="oldFormat">PGP 2.6.x compatibility required.</param>
         public PgpEncryptedDataGenerator(
             SymmetricKeyAlgorithmTag	encAlgorithm,
-            SecureRandom				rand,
+            SecureRandom				random,
             bool						oldFormat)
         {
+            if (random == null)
+                throw new ArgumentNullException(nameof(random));
+
             this.defAlgorithm = encAlgorithm;
-            this.rand = rand;
+            this.rand = random;
             this.oldFormat = oldFormat;
         }