KekIdentifier
using System;
namespace Org.BouncyCastle.Asn1.Cms
{
public class KekIdentifier : Asn1Encodable
{
private readonly Asn1OctetString m_keyIdentifier;
private readonly Asn1GeneralizedTime m_date;
private readonly OtherKeyAttribute m_other;
public Asn1OctetString KeyIdentifier => m_keyIdentifier;
public Asn1GeneralizedTime Date => m_date;
public OtherKeyAttribute Other => m_other;
public static KekIdentifier GetInstance(object obj)
{
if (obj == null)
return null;
KekIdentifier kekIdentifier = obj as KekIdentifier;
if (kekIdentifier != null)
return kekIdentifier;
return new KekIdentifier(Asn1Sequence.GetInstance(obj));
}
public static KekIdentifier GetInstance(Asn1TaggedObject obj, bool explicitly)
{
return new KekIdentifier(Asn1Sequence.GetInstance(obj, explicitly));
}
public static KekIdentifier GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new KekIdentifier(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
}
public KekIdentifier(byte[] keyIdentifier, Asn1GeneralizedTime date, OtherKeyAttribute other)
{
m_keyIdentifier = DerOctetString.FromContents(keyIdentifier);
m_date = date;
m_other = other;
}
[Obsolete("Use 'GetInstance' instead")]
public KekIdentifier(Asn1Sequence seq)
{
int count = seq.Count;
int sequencePosition = 0;
if (count < 1 || count > 3)
throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq");
m_keyIdentifier = Asn1OctetString.GetInstance(seq[sequencePosition++]);
m_date = Asn1Utilities.ReadOptional(seq, ref sequencePosition, Asn1GeneralizedTime.GetOptional);
m_other = Asn1Utilities.ReadOptional(seq, ref sequencePosition, OtherKeyAttribute.GetOptional);
if (sequencePosition != count)
throw new ArgumentException("Unexpected elements in sequence", "seq");
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(3);
asn1EncodableVector.Add(m_keyIdentifier);
asn1EncodableVector.AddOptional(m_date, m_other);
return new DerSequence(asn1EncodableVector);
}
}
}