EncryptedKey
using Org.BouncyCastle.Asn1.Cms;
using System;
namespace Org.BouncyCastle.Asn1.Crmf
{
public class EncryptedKey : Asn1Encodable, IAsn1Choice
{
private readonly EnvelopedData m_envelopedData;
private readonly EncryptedValue m_encryptedValue;
public virtual bool IsEncryptedValue => m_encryptedValue != null;
public virtual Asn1Encodable Value {
get {
if (m_encryptedValue != null)
return m_encryptedValue;
return m_envelopedData;
}
}
public static EncryptedKey GetInstance(object obj)
{
return Asn1Utilities.GetInstanceChoice(obj, GetOptional);
}
public static EncryptedKey GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return Asn1Utilities.GetInstanceChoice(taggedObject, declaredExplicit, GetInstance);
}
public static EncryptedKey GetOptional(Asn1Encodable element)
{
if (element == null)
throw new ArgumentNullException("element");
EncryptedKey encryptedKey = element as EncryptedKey;
if (encryptedKey != null)
return encryptedKey;
EncryptedValue optional = EncryptedValue.GetOptional(element);
if (optional != null)
return new EncryptedKey(optional);
Asn1TaggedObject optional2 = Asn1TaggedObject.GetOptional(element);
if (optional2 != null && optional2.HasContextTag(0))
return new EncryptedKey(EnvelopedData.GetTagged(optional2, false));
return null;
}
public static EncryptedKey GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance);
}
public EncryptedKey(EnvelopedData envelopedData)
{
m_envelopedData = envelopedData;
}
public EncryptedKey(EncryptedValue encryptedValue)
{
m_encryptedValue = encryptedValue;
}
public override Asn1Object ToAsn1Object()
{
if (m_encryptedValue != null)
return m_encryptedValue.ToAsn1Object();
return new DerTaggedObject(false, 0, m_envelopedData);
}
}
}