123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using System.Collections;
- using System.IO;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
- using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
- namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
- {
- /**
- * containing class for an CMS Authenticated Data object
- */
- public class CmsAuthenticatedData
- {
- internal RecipientInformationStore recipientInfoStore;
- internal ContentInfo contentInfo;
- private AlgorithmIdentifier macAlg;
- private Asn1Set authAttrs;
- private Asn1Set unauthAttrs;
- private byte[] mac;
- public CmsAuthenticatedData(
- byte[] authData)
- : this(CmsUtilities.ReadContentInfo(authData))
- {
- }
- public CmsAuthenticatedData(
- Stream authData)
- : this(CmsUtilities.ReadContentInfo(authData))
- {
- }
- public CmsAuthenticatedData(
- ContentInfo contentInfo)
- {
- this.contentInfo = contentInfo;
- AuthenticatedData authData = AuthenticatedData.GetInstance(contentInfo.Content);
- //
- // read the recipients
- //
- Asn1Set recipientInfos = authData.RecipientInfos;
- this.macAlg = authData.MacAlgorithm;
- //
- // read the authenticated content info
- //
- ContentInfo encInfo = authData.EncapsulatedContentInfo;
- CmsReadable readable = new CmsProcessableByteArray(
- Asn1OctetString.GetInstance(encInfo.Content).GetOctets());
- CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsAuthenticatedSecureReadable(
- this.macAlg, readable);
- //
- // build the RecipientInformationStore
- //
- this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
- recipientInfos, secureReadable);
- this.authAttrs = authData.AuthAttrs;
- this.mac = authData.Mac.GetOctets();
- this.unauthAttrs = authData.UnauthAttrs;
- }
- public byte[] GetMac()
- {
- return Arrays.Clone(mac);
- }
- public AlgorithmIdentifier MacAlgorithmID
- {
- get { return macAlg; }
- }
- /**
- * return the object identifier for the content MAC algorithm.
- */
- public string MacAlgOid
- {
- get { return macAlg.Algorithm.Id; }
- }
- /**
- * return a store of the intended recipients for this message
- */
- public RecipientInformationStore GetRecipientInfos()
- {
- return recipientInfoStore;
- }
- /**
- * return the ContentInfo
- */
- public ContentInfo ContentInfo
- {
- get { return contentInfo; }
- }
- /**
- * return a table of the digested attributes indexed by
- * the OID of the attribute.
- */
- public Asn1.Cms.AttributeTable GetAuthAttrs()
- {
- if (authAttrs == null)
- return null;
- return new Asn1.Cms.AttributeTable(authAttrs);
- }
- /**
- * return a table of the undigested attributes indexed by
- * the OID of the attribute.
- */
- public Asn1.Cms.AttributeTable GetUnauthAttrs()
- {
- if (unauthAttrs == null)
- return null;
- return new Asn1.Cms.AttributeTable(unauthAttrs);
- }
- /**
- * return the ASN.1 encoded representation of this object.
- */
- public byte[] GetEncoded()
- {
- return contentInfo.GetEncoded();
- }
- }
- }
- #pragma warning restore
- #endif
|