diff options
Diffstat (limited to 'crypto/src/openpgp')
-rw-r--r-- | crypto/src/openpgp/PgpCompressedData.cs | 23 | ||||
-rw-r--r-- | crypto/src/openpgp/PgpCompressedDataGenerator.cs | 58 | ||||
-rw-r--r-- | crypto/src/openpgp/PgpEncryptedDataGenerator.cs | 41 |
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; } |