diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-28 13:03:04 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-28 13:03:04 +0700 |
commit | 0b4ab10c4e7da41fc51fb4618291843d76d39941 (patch) | |
tree | 0433f0d50f2e31611e8aa8ec2cd0d67a8206a1e9 /crypto/src/cms/CMSCompressedDataStreamGenerator.cs | |
parent | DateTimeUtilities improvements: (diff) | |
download | BouncyCastle.NET-ed25519-0b4ab10c4e7da41fc51fb4618291843d76d39941.tar.xz |
Cleanup CMS compressed data
Diffstat (limited to '')
-rw-r--r-- | crypto/src/cms/CMSCompressedDataStreamGenerator.cs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs index 855367320..1594500cd 100644 --- a/crypto/src/cms/CMSCompressedDataStreamGenerator.cs +++ b/crypto/src/cms/CMSCompressedDataStreamGenerator.cs @@ -26,13 +26,10 @@ namespace Org.BouncyCastle.Cms */ public class CmsCompressedDataStreamGenerator { - public const string ZLibOid = "1.2.840.113549.1.9.16.3.8"; + public static readonly string ZLib = CmsObjectIdentifiers.ZlibCompress.Id; - [Obsolete("Use 'ZLibOid' instead")] - public const string ZLib = ZLibOid; + private int _bufferSize; - private int _bufferSize; - /** * base constructor */ @@ -45,24 +42,27 @@ namespace Org.BouncyCastle.Cms * * @param bufferSize length of octet strings to buffer the data. */ - public void SetBufferSize( - int bufferSize) + public void SetBufferSize(int bufferSize) { _bufferSize = bufferSize; } - public Stream Open( - Stream outStream, - string compressionOID) + public Stream Open(Stream outStream) + { + return Open(outStream, CmsObjectIdentifiers.Data.Id, ZLib); + } + + public Stream Open(Stream outStream, string compressionOid) { - return Open(outStream, CmsObjectIdentifiers.Data.Id, compressionOID); + return Open(outStream, CmsObjectIdentifiers.Data.Id, compressionOid); } - public Stream Open( - Stream outStream, - string contentOID, - string compressionOID) + public Stream Open(Stream outStream, string contentOid, string compressionOid) { + if (ZLib != compressionOid) + throw new ArgumentException("Unsupported compression algorithm: " + compressionOid, + nameof(compressionOid)); + BerSequenceGenerator sGen = new BerSequenceGenerator(outStream); sGen.AddObject(CmsObjectIdentifiers.CompressedData); @@ -77,14 +77,14 @@ namespace Org.BouncyCastle.Cms cGen.AddObject(new DerInteger(0)); // CompressionAlgorithmIdentifier - cGen.AddObject(new AlgorithmIdentifier(new DerObjectIdentifier(ZLib))); + cGen.AddObject(new AlgorithmIdentifier(CmsObjectIdentifiers.ZlibCompress)); // // Encapsulated ContentInfo // BerSequenceGenerator eiGen = new BerSequenceGenerator(cGen.GetRawOutputStream()); - eiGen.AddObject(new DerObjectIdentifier(contentOID)); + eiGen.AddObject(new DerObjectIdentifier(contentOid)); Stream octetStream = CmsUtilities.CreateBerOctetOutputStream( eiGen.GetRawOutputStream(), 0, true, _bufferSize); |