diff options
Diffstat (limited to 'crypto/src/asn1/ess/ContentIdentifier.cs')
-rw-r--r-- | crypto/src/asn1/ess/ContentIdentifier.cs | 66 |
1 files changed, 26 insertions, 40 deletions
diff --git a/crypto/src/asn1/ess/ContentIdentifier.cs b/crypto/src/asn1/ess/ContentIdentifier.cs index 430185e11..0520653f3 100644 --- a/crypto/src/asn1/ess/ContentIdentifier.cs +++ b/crypto/src/asn1/ess/ContentIdentifier.cs @@ -1,54 +1,43 @@ using System; -using Org.BouncyCastle.Utilities; - namespace Org.BouncyCastle.Asn1.Ess { - public class ContentIdentifier + public class ContentIdentifier : Asn1Encodable { - private Asn1OctetString value; - - public static ContentIdentifier GetInstance( - object o) - { - if (o == null || o is ContentIdentifier) - { - return (ContentIdentifier) o; - } - - if (o is Asn1OctetString) - { - return new ContentIdentifier((Asn1OctetString) o); - } - - throw new ArgumentException( - "unknown object in 'ContentIdentifier' factory : " - + Platform.GetTypeName(o) + "."); - } - - /** + public static ContentIdentifier GetInstance(object o) + { + if (o == null) + return null; + if (o is ContentIdentifier contentIdentifier) + return contentIdentifier; + return new ContentIdentifier(Asn1OctetString.GetInstance(o)); + } + + public static ContentIdentifier GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) + { + return new ContentIdentifier(Asn1OctetString.GetInstance(taggedObject, declaredExplicit)); + } + + private readonly Asn1OctetString m_value; + + /** * Create from OCTET STRING whose octets represent the identifier. */ - public ContentIdentifier( - Asn1OctetString value) - { - this.value = value; - } + public ContentIdentifier(Asn1OctetString value) + { + m_value = value ?? throw new ArgumentNullException(nameof(value)); + } - /** + /** * Create from byte array representing the identifier. */ - public ContentIdentifier( - byte[] value) + public ContentIdentifier(byte[] value) : this(new DerOctetString(value)) { } - public Asn1OctetString Value - { - get { return value; } - } + public Asn1OctetString Value => m_value; /** * The definition of ContentIdentifier is @@ -59,9 +48,6 @@ namespace Org.BouncyCastle.Asn1.Ess * member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9) * smime(16) id-aa(2) 7 } */ - public override Asn1Object ToAsn1Object() - { - return value; - } + public override Asn1Object ToAsn1Object() => m_value; } } |