PrivateKeyUsagePeriod
using System;
namespace Org.BouncyCastle.Asn1.X509
{
public class PrivateKeyUsagePeriod : Asn1Encodable
{
private readonly Asn1GeneralizedTime m_notBefore;
private readonly Asn1GeneralizedTime m_notAfter;
public Asn1GeneralizedTime NotBefore => m_notBefore;
public Asn1GeneralizedTime NotAfter => m_notAfter;
public static PrivateKeyUsagePeriod GetInstance(object obj)
{
if (obj == null)
return null;
PrivateKeyUsagePeriod privateKeyUsagePeriod = obj as PrivateKeyUsagePeriod;
if (privateKeyUsagePeriod != null)
return privateKeyUsagePeriod;
X509Extension x509Extension = obj as X509Extension;
if (x509Extension != null)
return GetInstance(X509Extension.ConvertValueToObject(x509Extension));
return new PrivateKeyUsagePeriod(Asn1Sequence.GetInstance(obj));
}
public static PrivateKeyUsagePeriod GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new PrivateKeyUsagePeriod(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
}
public static PrivateKeyUsagePeriod GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return new PrivateKeyUsagePeriod(Asn1Sequence.GetTagged(taggedObject, declaredExplicit));
}
private PrivateKeyUsagePeriod(Asn1Sequence seq)
{
int count = seq.Count;
int sequencePosition = 0;
if (count < 0 || count > 2)
throw new ArgumentException("Bad sequence size: " + count.ToString(), "seq");
m_notBefore = Asn1Utilities.ReadOptionalContextTagged(seq, ref sequencePosition, 0, false, Asn1GeneralizedTime.GetTagged);
m_notAfter = Asn1Utilities.ReadOptionalContextTagged(seq, ref sequencePosition, 1, false, Asn1GeneralizedTime.GetTagged);
if (sequencePosition != count)
throw new ArgumentException("Unexpected elements in sequence", "seq");
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(2);
asn1EncodableVector.AddOptionalTagged(false, 0, m_notBefore);
asn1EncodableVector.AddOptionalTagged(false, 1, m_notAfter);
return new DerSequence(asn1EncodableVector);
}
}
}