SignerInfo
using Org.BouncyCastle.Asn1.X509;
using System;
namespace Org.BouncyCastle.Asn1.Pkcs
{
public class SignerInfo : Asn1Encodable
{
private readonly DerInteger m_version;
private readonly IssuerAndSerialNumber m_issuerAndSerialNumber;
private readonly AlgorithmIdentifier m_digAlgorithm;
private readonly Asn1Set m_authenticatedAttributes;
private readonly AlgorithmIdentifier m_digEncryptionAlgorithm;
private readonly Asn1OctetString m_encryptedDigest;
private readonly Asn1Set m_unauthenticatedAttributes;
public DerInteger Version => m_version;
public IssuerAndSerialNumber IssuerAndSerialNumber => m_issuerAndSerialNumber;
public Asn1Set AuthenticatedAttributes => m_authenticatedAttributes;
public AlgorithmIdentifier DigestAlgorithm => m_digAlgorithm;
public Asn1OctetString EncryptedDigest => m_encryptedDigest;
public AlgorithmIdentifier DigestEncryptionAlgorithm => m_digEncryptionAlgorithm;
public Asn1Set UnauthenticatedAttributes => m_unauthenticatedAttributes;
public static SignerInfo GetInstance(object obj)
{
if (obj == null)
return null;
SignerInfo signerInfo = obj as SignerInfo;
if (signerInfo != null)
return signerInfo;
return new SignerInfo(Asn1Sequence.GetInstance(obj));
}
public static SignerInfo GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new SignerInfo(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
}
public static SignerInfo GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new SignerInfo(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
}
[Obsolete("Use 'GetInstance' instead")]
public SignerInfo(Asn1Sequence seq)
{
int count = seq.Count;
int sequencePosition = 0;
if (count < 5 || count > 7)
throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq");
m_version = DerInteger.GetInstance(seq[sequencePosition++]);
m_issuerAndSerialNumber = IssuerAndSerialNumber.GetInstance(seq[sequencePosition++]);
m_digAlgorithm = AlgorithmIdentifier.GetInstance(seq[sequencePosition++]);
m_authenticatedAttributes = Asn1Utilities.ReadOptionalContextTagged(seq, ref sequencePosition, 0, false, Asn1Set.GetTagged);
m_digEncryptionAlgorithm = AlgorithmIdentifier.GetInstance(seq[sequencePosition++]);
m_encryptedDigest = Asn1OctetString.GetInstance(seq[sequencePosition++]);
m_unauthenticatedAttributes = Asn1Utilities.ReadOptionalContextTagged(seq, ref sequencePosition, 1, false, Asn1Set.GetTagged);
if (sequencePosition != count)
throw new ArgumentException("Unexpected elements in sequence", "seq");
}
public SignerInfo(DerInteger version, IssuerAndSerialNumber issuerAndSerialNumber, AlgorithmIdentifier digAlgorithm, Asn1Set authenticatedAttributes, AlgorithmIdentifier digEncryptionAlgorithm, Asn1OctetString encryptedDigest, Asn1Set unauthenticatedAttributes)
{
if (version == null)
throw new ArgumentNullException("version");
m_version = version;
if (issuerAndSerialNumber == null)
throw new ArgumentNullException("issuerAndSerialNumber");
m_issuerAndSerialNumber = issuerAndSerialNumber;
if (digAlgorithm == null)
throw new ArgumentNullException("digAlgorithm");
m_digAlgorithm = digAlgorithm;
m_authenticatedAttributes = authenticatedAttributes;
if (digEncryptionAlgorithm == null)
throw new ArgumentNullException("digEncryptionAlgorithm");
m_digEncryptionAlgorithm = digEncryptionAlgorithm;
if (encryptedDigest == null)
throw new ArgumentNullException("encryptedDigest");
m_encryptedDigest = encryptedDigest;
m_unauthenticatedAttributes = unauthenticatedAttributes;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(7);
asn1EncodableVector.Add(m_version, m_issuerAndSerialNumber, m_digAlgorithm);
asn1EncodableVector.AddOptionalTagged(false, 0, m_authenticatedAttributes);
asn1EncodableVector.Add(m_digEncryptionAlgorithm, m_encryptedDigest);
asn1EncodableVector.AddOptionalTagged(false, 1, m_unauthenticatedAttributes);
return new DerSequence(asn1EncodableVector);
}
}
}