diff options
-rw-r--r-- | crypto/src/asn1/cms/CMSObjectIdentifiers.cs | 3 | ||||
-rw-r--r-- | crypto/src/asn1/pkcs/PKCSObjectIdentifiers.cs | 11 | ||||
-rw-r--r-- | crypto/src/cms/CMSCompressedDataGenerator.cs | 15 | ||||
-rw-r--r-- | crypto/src/cms/CMSCompressedDataStreamGenerator.cs | 34 |
4 files changed, 32 insertions, 31 deletions
diff --git a/crypto/src/asn1/cms/CMSObjectIdentifiers.cs b/crypto/src/asn1/cms/CMSObjectIdentifiers.cs index 2ad0a3c7c..6f4f8fb5e 100644 --- a/crypto/src/asn1/cms/CMSObjectIdentifiers.cs +++ b/crypto/src/asn1/cms/CMSObjectIdentifiers.cs @@ -13,7 +13,8 @@ namespace Org.BouncyCastle.Asn1.Cms public static readonly DerObjectIdentifier AuthenticatedData = PkcsObjectIdentifiers.IdCTAuthData; public static readonly DerObjectIdentifier CompressedData = PkcsObjectIdentifiers.IdCTCompressedData; public static readonly DerObjectIdentifier AuthEnvelopedData = PkcsObjectIdentifiers.IdCTAuthEnvelopedData; - public static readonly DerObjectIdentifier timestampedData = PkcsObjectIdentifiers.IdCTTimestampedData; + public static readonly DerObjectIdentifier TimestampedData = PkcsObjectIdentifiers.IdCTTimestampedData; + public static readonly DerObjectIdentifier ZlibCompress = PkcsObjectIdentifiers.IdAlgZlibCompress; /** * The other Revocation Info arc diff --git a/crypto/src/asn1/pkcs/PKCSObjectIdentifiers.cs b/crypto/src/asn1/pkcs/PKCSObjectIdentifiers.cs index 1a6a5417a..570e0ded7 100644 --- a/crypto/src/asn1/pkcs/PKCSObjectIdentifiers.cs +++ b/crypto/src/asn1/pkcs/PKCSObjectIdentifiers.cs @@ -138,11 +138,12 @@ namespace Org.BouncyCastle.Asn1.Pkcs public static readonly DerObjectIdentifier IdAlg = IdSmime.Branch("3"); - public static readonly DerObjectIdentifier IdAlgEsdh = IdAlg.Branch("5"); - public static readonly DerObjectIdentifier IdAlgCms3DesWrap = IdAlg.Branch("6"); - public static readonly DerObjectIdentifier IdAlgCmsRC2Wrap = IdAlg.Branch("7"); - public static readonly DerObjectIdentifier IdAlgPwriKek = IdAlg.Branch("9"); - public static readonly DerObjectIdentifier IdAlgSsdh = IdAlg.Branch("10"); + public static readonly DerObjectIdentifier IdAlgEsdh = IdAlg.Branch("5"); + public static readonly DerObjectIdentifier IdAlgCms3DesWrap = IdAlg.Branch("6"); + public static readonly DerObjectIdentifier IdAlgCmsRC2Wrap = IdAlg.Branch("7"); + public static readonly DerObjectIdentifier IdAlgZlibCompress = IdAlg.Branch("8"); + public static readonly DerObjectIdentifier IdAlgPwriKek = IdAlg.Branch("9"); + public static readonly DerObjectIdentifier IdAlgSsdh = IdAlg.Branch("10"); /* * <pre> diff --git a/crypto/src/cms/CMSCompressedDataGenerator.cs b/crypto/src/cms/CMSCompressedDataGenerator.cs index 872c4a144..70515e8d3 100644 --- a/crypto/src/cms/CMSCompressedDataGenerator.cs +++ b/crypto/src/cms/CMSCompressedDataGenerator.cs @@ -21,10 +21,7 @@ namespace Org.BouncyCastle.Cms */ public class CmsCompressedDataGenerator { - public const string ZLibOid = "1.2.840.113549.1.9.16.3.8"; - - [Obsolete("Use 'ZLibOid' instead")] - public const string ZLib = ZLibOid; + public static readonly string ZLib = CmsObjectIdentifiers.ZlibCompress.Id; public CmsCompressedDataGenerator() { @@ -33,10 +30,12 @@ namespace Org.BouncyCastle.Cms /** * 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; @@ -49,7 +48,7 @@ namespace Org.BouncyCastle.Cms Platform.Dispose(zOut); - comAlgId = new AlgorithmIdentifier(new DerObjectIdentifier(compressionOid)); + comAlgId = new AlgorithmIdentifier(CmsObjectIdentifiers.ZlibCompress); comOcts = new BerOctetString(bOut.ToArray()); } catch (IOException e) 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); |