From 94cd875bf77b6883978d458b3f7b43d838712e7e Mon Sep 17 00:00:00 2001 From: Konradsop Date: Thu, 30 Jul 2026 17:00:02 +0200 Subject: [PATCH] Add XML documentation for CMS CompressedData --- crypto/src/cms/CMSCompressedData.cs | 53 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/crypto/src/cms/CMSCompressedData.cs b/crypto/src/cms/CMSCompressedData.cs index 4f2fea04c..872604fb2 100644 --- a/crypto/src/cms/CMSCompressedData.cs +++ b/crypto/src/cms/CMSCompressedData.cs @@ -3,67 +3,76 @@ using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Cms; +using Org.BouncyCastle.Utilities.IO; using Org.BouncyCastle.Utilities.IO.Compression; namespace Org.BouncyCastle.Cms { - /// Containing class for a CMS CompressedData object. + /// + /// Represents a CMS CompressedData message. Parse an encoded message, then decompress via + /// or . + /// public class CmsCompressedData { private readonly ContentInfo m_contentInfo; private readonly CompressedData m_compressedData; + /// Creates an instance from an encoded CompressedData message. + /// The DER-encoded CMS ContentInfo bytes. public CmsCompressedData(byte[] compressedData) : this(CmsUtilities.ReadContentInfo(compressedData)) { } + /// Creates an instance from an encoded CompressedData message. + /// A stream containing the DER-encoded CMS ContentInfo. public CmsCompressedData(Stream compressedDataStream) : this(CmsUtilities.ReadContentInfo(compressedDataStream)) { } + /// Creates an instance from a parsed CMS ContentInfo structure. + /// The CMS ContentInfo wrapping a CompressedData object. + /// is null. public CmsCompressedData(ContentInfo contentInfo) { m_contentInfo = contentInfo ?? throw new ArgumentNullException(nameof(contentInfo)); m_compressedData = CmsUtilities.SafeGetContent(contentInfo, CompressedData.GetInstance); } + /// Gets the outer CMS ContentInfo content type (compressed-data). public DerObjectIdentifier ContentType => m_contentInfo.ContentType; + /// Gets the content type of the encapsulated content before compression. public DerObjectIdentifier CompressedContentType => m_compressedData.EncapContentInfo.ContentType; + /// Returns a typed stream over the decompressed content. + /// A stream over the uncompressed content. public CmsTypedStream GetContentStream() => new CmsTypedStream(CompressedContentType, Decompress()); - /** - * Return the uncompressed content. - * - * @return the uncompressed content - * @throws CmsException if there is an exception uncompressing the data. - */ + /// Returns the decompressed content. + /// The uncompressed content octets. + /// Thrown if the compressed data cannot be read. public byte[] GetContent() => Decompress(zIn => CmsUtilities.StreamToByteArray(zIn)); - /** - * Return the uncompressed content, throwing an exception if the data size - * is greater than the passed in limit. If the content is exceeded getCause() - * on the CMSException will contain a StreamOverflowException - * - * @param limit maximum number of bytes to read - * @return the content read - * @throws CMSException if there is an exception uncompressing the data. - */ + /// + /// Returns the decompressed content, throwing if the uncompressed size would exceed . + /// + /// The maximum number of decompressed bytes to read. + /// The uncompressed content octets. + /// + /// Thrown if the compressed data cannot be read. If is exceeded, the inner exception + /// may be a . + /// public byte[] GetContent(int limit) => Decompress(zIn => CmsUtilities.StreamToByteArray(zIn, limit)); + /// Gets the underlying ASN.1 CompressedData structure. public CompressedData CompressedData => m_compressedData; - /** - * return the ContentInfo - */ + /// Gets the CMS ContentInfo wrapper for this message. public ContentInfo ContentInfo => m_contentInfo; - /** - * return the ASN.1 encoded representation of this object. - */ + /// Returns the DER encoding of this message. public byte[] GetEncoded() => m_contentInfo.GetEncoded(); private byte[] Decompress(Func converter)