diff --git a/crypto/src/cms/CMSAuthenticatedData.cs b/crypto/src/cms/CMSAuthenticatedData.cs index 2e9db1503..1e92a890d 100644 --- a/crypto/src/cms/CMSAuthenticatedData.cs +++ b/crypto/src/cms/CMSAuthenticatedData.cs @@ -8,7 +8,11 @@ namespace Org.BouncyCastle.Cms { - /// Containing class for a CMS AuthenticatedData object. + /// + /// Represents a CMS AuthenticatedData (MAC-protected) message. Parse an encoded message, obtain recipients from + /// , match one with , recover content via + /// , and verify integrity with . + /// public class CmsAuthenticatedData { private readonly ContentInfo m_contentInfo; @@ -20,16 +24,25 @@ public class CmsAuthenticatedData private Asn1.Cms.AttributeTable m_authAttributeTable; private Asn1.Cms.AttributeTable m_unauthAttributeTable; + /// Creates an instance from an encoded AuthenticatedData message. + /// The DER-encoded CMS ContentInfo bytes. public CmsAuthenticatedData(byte[] authData) : this(CmsUtilities.ReadContentInfo(authData)) { } + /// Creates an instance from an encoded AuthenticatedData message. + /// A stream containing the DER-encoded CMS ContentInfo. public CmsAuthenticatedData(Stream authData) : this(CmsUtilities.ReadContentInfo(authData)) { } + /// Creates an instance from a parsed CMS ContentInfo structure. + /// The CMS ContentInfo wrapping an AuthenticatedData object. + /// is null. + /// Authenticated attributes cannot be validated. + /// Authenticated attributes are present in the message. public CmsAuthenticatedData(ContentInfo contentInfo) { m_contentInfo = contentInfo ?? throw new ArgumentNullException(nameof(contentInfo)); @@ -82,32 +95,34 @@ public CmsAuthenticatedData(ContentInfo contentInfo) //} } + /// Gets the underlying ASN.1 AuthenticatedData structure. public AuthenticatedData AuthenticatedData => m_authenticatedData; + /// Gets originator certificates and CRLs carried in the message, or null if absent. public OriginatorInformation OriginatorInformation => m_originatorInformation; + /// Returns a copy of the message authentication code (MAC) value. public byte[] GetMac() => Arrays.Clone(m_authenticatedData.Mac.GetOctets()); + /// Gets the MAC algorithm identifier. public AlgorithmIdentifier MacAlgorithmID => m_authenticatedData.MacAlgorithm; - /** - * return the object identifier for the content MAC algorithm. - */ + /// Return the object identifier for the MAC algorithm. // TODO[api] Return the OID itself public string MacAlgOid => MacAlgorithmID.Algorithm.GetID(); - /** - * return a store of the intended recipients for this message - */ + /// Returns a store of the intended recipients for this message. public RecipientInformationStore GetRecipientInfos() => m_recipientInfoStore; + /// Gets the CMS ContentInfo wrapper for this message. public ContentInfo ContentInfo => m_contentInfo; - /// Return a table of the digested attributes indexed by the OID of the attribute. + /// Return a table of the authenticated attributes. Use instead. + /// [Obsolete("Use 'AuthAttributes' property instead")] public Asn1.Cms.AttributeTable GetAuthAttrs() => AuthAttributes; - /// Return a table of the authenticated attributes - indexed by the OID of the attribute. + /// Gets a table of authenticated attributes indexed by attribute OID. public Asn1.Cms.AttributeTable AuthAttributes { get @@ -120,11 +135,12 @@ public Asn1.Cms.AttributeTable AuthAttributes } } - /// Return a table of the undigested attributes indexed by the OID of the attribute. - [Obsolete("Use 'AuthAttributes' property instead")] + /// Return a table of the unauthenticated attributes. Use instead. + /// + [Obsolete("Use 'UnauthAttributes' property instead")] public Asn1.Cms.AttributeTable GetUnauthAttrs() => UnauthAttributes; - /// Return a table of the unauthenticated attributes - indexed by the OID of the attribute. + /// Gets a table of unauthenticated attributes indexed by attribute OID. public Asn1.Cms.AttributeTable UnauthAttributes { get @@ -137,9 +153,14 @@ public Asn1.Cms.AttributeTable UnauthAttributes } } - /// Return the ASN.1 encoded representation of this object. + /// Returns the DER encoding of this message. public byte[] GetEncoded() => m_contentInfo.GetEncoded(); + /// + /// Returns the message-digest value carried in authenticated attributes, or null if none is present. + /// + /// A copy of the message-digest octets, or null when the attribute is absent. + /// Authenticated attributes are present but invalid. public byte[] GetContentDigest() { // TODO Full validation; this is syntactic validation on access only; the actual digest is not checked