diff options
Diffstat (limited to 'crypto/src')
-rw-r--r-- | crypto/src/asn1/x500/AttributeTypeAndValue.cs | 57 | ||||
-rw-r--r-- | crypto/src/asn1/x500/DirectoryString.cs | 26 | ||||
-rw-r--r-- | crypto/src/asn1/x500/Rdn.cs | 3 |
3 files changed, 40 insertions, 46 deletions
diff --git a/crypto/src/asn1/x500/AttributeTypeAndValue.cs b/crypto/src/asn1/x500/AttributeTypeAndValue.cs index eb6b3ca30..d7e684d86 100644 --- a/crypto/src/asn1/x500/AttributeTypeAndValue.cs +++ b/crypto/src/asn1/x500/AttributeTypeAndValue.cs @@ -8,42 +8,44 @@ namespace Org.BouncyCastle.Asn1.X500 public class AttributeTypeAndValue : Asn1Encodable { - private readonly DerObjectIdentifier type; - private readonly Asn1Encodable value; - - private AttributeTypeAndValue(Asn1Sequence seq) - { - type = (DerObjectIdentifier)seq[0]; - value = seq[1]; - } - public static AttributeTypeAndValue GetInstance(object obj) { - if (obj is AttributeTypeAndValue) - return (AttributeTypeAndValue)obj; - if (null != obj) - return new AttributeTypeAndValue(Asn1Sequence.GetInstance(obj)); - throw new ArgumentNullException("obj"); + if (obj == null) + return null; + if (obj is AttributeTypeAndValue attributeTypeAndValue) + return attributeTypeAndValue; + return new AttributeTypeAndValue(Asn1Sequence.GetInstance(obj)); } - public AttributeTypeAndValue( - DerObjectIdentifier type, - Asn1Encodable value) - { - this.type = type; - this.value = value; - } + public static AttributeTypeAndValue GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new AttributeTypeAndValue(Asn1Sequence.GetInstance(taggedObject, declaredExplicit)); + + public static AttributeTypeAndValue GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new AttributeTypeAndValue(Asn1Sequence.GetTagged(taggedObject, declaredExplicit)); - public virtual DerObjectIdentifier Type + private readonly DerObjectIdentifier m_type; + private readonly Asn1Encodable m_value; + + private AttributeTypeAndValue(Asn1Sequence seq) { - get { return type; } + int count = seq.Count; + if (count != 2) + throw new ArgumentException("Bad sequence size: " + count, nameof(seq)); + + m_type = DerObjectIdentifier.GetInstance(seq[0]); + m_value = seq[1]; } - public virtual Asn1Encodable Value + public AttributeTypeAndValue(DerObjectIdentifier type, Asn1Encodable value) { - get { return value; } + m_type = type ?? throw new ArgumentNullException(nameof(type)); + m_value = value ?? throw new ArgumentNullException(nameof(value)); } + public virtual DerObjectIdentifier Type => m_type; + + public virtual Asn1Encodable Value => m_value; + /** * <pre> * AttributeTypeAndValue ::= SEQUENCE { @@ -52,9 +54,6 @@ namespace Org.BouncyCastle.Asn1.X500 * </pre> * @return a basic ASN.1 object representation. */ - public override Asn1Object ToAsn1Object() - { - return new DerSequence(type, value); - } + public override Asn1Object ToAsn1Object() => new DerSequence(m_type, m_value); } } diff --git a/crypto/src/asn1/x500/DirectoryString.cs b/crypto/src/asn1/x500/DirectoryString.cs index c622113d4..aefb56512 100644 --- a/crypto/src/asn1/x500/DirectoryString.cs +++ b/crypto/src/asn1/x500/DirectoryString.cs @@ -4,11 +4,9 @@ using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Asn1.X500 { - public class DirectoryString + public class DirectoryString : Asn1Encodable, IAsn1Choice, IAsn1String { - private readonly DerStringBase str; - public static DirectoryString GetInstance(object obj) { if (obj == null) @@ -55,23 +53,20 @@ namespace Org.BouncyCastle.Asn1.X500 ?? (DerStringBase)null; } - private DirectoryString( - DerStringBase str) - { - this.str = str; - } + private readonly DerStringBase m_str; - public DirectoryString( - string str) + private DirectoryString(DerStringBase str) { - this.str = new DerUtf8String(str); + m_str = str; } - public string GetString() + public DirectoryString(string str) { - return str.GetString(); + m_str = new DerUtf8String(str); } + public string GetString() => m_str.GetString(); + /** * <pre> * DirectoryString ::= CHOICE { @@ -82,9 +77,6 @@ namespace Org.BouncyCastle.Asn1.X500 * bmpString BMPString (SIZE (1..MAX)) } * </pre> */ - public override Asn1Object ToAsn1Object() - { - return str.ToAsn1Object(); - } + public override Asn1Object ToAsn1Object() => m_str.ToAsn1Object(); } } diff --git a/crypto/src/asn1/x500/Rdn.cs b/crypto/src/asn1/x500/Rdn.cs index 23537e1ae..e3dd586e9 100644 --- a/crypto/src/asn1/x500/Rdn.cs +++ b/crypto/src/asn1/x500/Rdn.cs @@ -18,6 +18,9 @@ namespace Org.BouncyCastle.Asn1.X500 public static Rdn GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) => new Rdn(Asn1Set.GetInstance(taggedObject, declaredExplicit)); + public static Rdn GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) => + new Rdn(Asn1Set.GetTagged(taggedObject, declaredExplicit)); + private readonly Asn1Set m_values; private Rdn(Asn1Set values) |