diff options
Diffstat (limited to 'crypto/src/asn1/x500/Rdn.cs')
-rw-r--r-- | crypto/src/asn1/x500/Rdn.cs | 67 |
1 files changed, 24 insertions, 43 deletions
diff --git a/crypto/src/asn1/x500/Rdn.cs b/crypto/src/asn1/x500/Rdn.cs index 4881d0890..069a592a5 100644 --- a/crypto/src/asn1/x500/Rdn.cs +++ b/crypto/src/asn1/x500/Rdn.cs @@ -8,20 +8,24 @@ namespace Org.BouncyCastle.Asn1.X500 public class Rdn : Asn1Encodable { - private readonly Asn1Set values; - - private Rdn(Asn1Set values) + public static Rdn GetInstance(object obj) { - this.values = values; + if (obj == null) + return null; + if (obj is Rdn rdn) + return rdn; + return new Rdn(Asn1Set.GetInstance(obj)); } - public static Rdn GetInstance(object obj) + public static Rdn GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new Rdn(Asn1Set.GetInstance(taggedObject, declaredExplicit)); + + private readonly Asn1Set m_values; + + private Rdn(Asn1Set values) { - if (obj is Rdn) - return (Rdn)obj; - if (null != obj) - return new Rdn(Asn1Set.GetInstance(obj)); - return null; + // TODO Require minimum size of 1? + m_values = values; } /** @@ -31,13 +35,13 @@ namespace Org.BouncyCastle.Asn1.X500 * @param value RDN value. */ public Rdn(DerObjectIdentifier oid, Asn1Encodable value) + : this(new AttributeTypeAndValue(oid, value)) { - this.values = new DerSet(new DerSequence(oid, value)); } public Rdn(AttributeTypeAndValue attrTAndV) { - this.values = new DerSet(attrTAndV); + m_values = new DerSet(attrTAndV); } /** @@ -47,43 +51,23 @@ namespace Org.BouncyCastle.Asn1.X500 */ public Rdn(AttributeTypeAndValue[] aAndVs) { - this.values = new DerSet(aAndVs); + m_values = new DerSet(aAndVs); } - public virtual bool IsMultiValued - { - get { return this.values.Count > 1; } - } + public virtual bool IsMultiValued => m_values.Count > 1; /** * Return the number of AttributeTypeAndValue objects in this RDN, * * @return size of RDN, greater than 1 if multi-valued. */ - public virtual int Count - { - get { return this.values.Count; } - } - - public virtual AttributeTypeAndValue GetFirst() - { - if (this.values.Count == 0) - return null; + public virtual int Count => m_values.Count; - return AttributeTypeAndValue.GetInstance(this.values[0]); - } + public virtual AttributeTypeAndValue GetFirst() => + m_values.Count == 0 ? null : AttributeTypeAndValue.GetInstance(m_values[0]); - public virtual AttributeTypeAndValue[] GetTypesAndValues() - { - AttributeTypeAndValue[] tmp = new AttributeTypeAndValue[values.Count]; - - for (int i = 0; i < tmp.Length; ++i) - { - tmp[i] = AttributeTypeAndValue.GetInstance(values[i]); - } - - return tmp; - } + public virtual AttributeTypeAndValue[] GetTypesAndValues() => + m_values.MapElements(AttributeTypeAndValue.GetInstance); /** * <pre> @@ -96,9 +80,6 @@ namespace Org.BouncyCastle.Asn1.X500 * </pre> * @return this object as its ASN1Primitive type */ - public override Asn1Object ToAsn1Object() - { - return values; - } + public override Asn1Object ToAsn1Object() => m_values; } } |