DistributionPointName
using System;
using System.Text;
namespace Org.BouncyCastle.Asn1.X509
{
public class DistributionPointName : Asn1Encodable, IAsn1Choice
{
public const int FullName = 0;
public const int NameRelativeToCrlIssuer = 1;
private readonly int m_type;
private readonly Asn1Encodable m_name;
[Obsolete("Use 'Type' instead")]
public int PointType {
get {
return m_type;
}
}
public Asn1Encodable Name => m_name;
public int Type => m_type;
public static DistributionPointName GetInstance(object obj)
{
return Asn1Utilities.GetInstanceChoice(obj, GetOptional);
}
public static DistributionPointName GetInstance(Asn1TaggedObject obj, bool explicitly)
{
return Asn1Utilities.GetInstanceChoice(obj, explicitly, GetInstance);
}
public static DistributionPointName GetOptional(Asn1Encodable element)
{
if (element == null)
throw new ArgumentNullException("element");
DistributionPointName distributionPointName = element as DistributionPointName;
if (distributionPointName != null)
return distributionPointName;
Asn1TaggedObject optional = Asn1TaggedObject.GetOptional(element);
if (optional != null) {
Asn1Encodable optionalBaseObject = GetOptionalBaseObject(optional);
if (optionalBaseObject != null)
return new DistributionPointName(optional.TagNo, optionalBaseObject);
}
return null;
}
public static DistributionPointName GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
return Asn1Utilities.GetTaggedChoice(taggedObject, declaredExplicit, GetInstance);
}
private static Asn1Encodable GetOptionalBaseObject(Asn1TaggedObject taggedObject)
{
if (taggedObject.HasContextTag()) {
switch (taggedObject.TagNo) {
case 0:
return GeneralNames.GetInstance(taggedObject, false);
case 1:
return Asn1Set.GetInstance(taggedObject, false);
}
}
return null;
}
public DistributionPointName(GeneralNames name)
: this(0, name)
{
}
public DistributionPointName(int type, Asn1Encodable name)
{
m_type = type;
m_name = name;
}
public override Asn1Object ToAsn1Object()
{
return new DerTaggedObject(false, m_type, m_name);
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("DistributionPointName: [");
if (m_type == 0)
AppendObject(stringBuilder, "fullName", m_name.ToString());
else
AppendObject(stringBuilder, "nameRelativeToCRLIssuer", m_name.ToString());
stringBuilder.AppendLine("]");
return stringBuilder.ToString();
}
private void AppendObject(StringBuilder buf, string name, string val)
{
string value = " ";
buf.Append(value);
buf.Append(name);
buf.AppendLine(":");
buf.Append(value);
buf.Append(value);
buf.Append(val);
buf.AppendLine();
}
}
}