using System;
using System.Collections;
using System.IO;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Utilities;
namespace 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 encapsulated content info
//
ContentInfo encInfo = authData.EncapsulatedContentInfo;
this.macAlg = authData.MacAlgorithm;
this.mac = authData.Mac.GetOctets();
//
// load the RecipientInfoStore
//
byte[] contentOctets = Asn1OctetString.GetInstance(encInfo.Content).GetOctets();
IList infos = CmsEnvelopedHelper.ReadRecipientInfos(
authData.RecipientInfos, contentOctets, null, macAlg, null);
this.authAttrs = authData.AuthAttrs;
this.recipientInfoStore = new RecipientInformationStore(infos);
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.ObjectID.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();
}
}
}
|