diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-11-18 13:46:18 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2021-11-18 13:46:18 +0700 |
commit | 4fccb8f490eefe7181558b2c3376ab23c33632ee (patch) | |
tree | fe8c1877bb5567cb4823823af77e5c8a38423db8 /crypto/src/asn1/Asn1ObjectDescriptor.cs | |
parent | ASN.1: Staged encoding (diff) | |
download | BouncyCastle.NET-ed25519-4fccb8f490eefe7181558b2c3376ab23c33632ee.tar.xz |
ASN.1: Port of bc-java TYPE instances
- we use Meta.Instance here due to syntax restrictions - also reworked some ASN.1 string types
Diffstat (limited to 'crypto/src/asn1/Asn1ObjectDescriptor.cs')
-rw-r--r-- | crypto/src/asn1/Asn1ObjectDescriptor.cs | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/crypto/src/asn1/Asn1ObjectDescriptor.cs b/crypto/src/asn1/Asn1ObjectDescriptor.cs index 289a0e16f..9c99f441e 100644 --- a/crypto/src/asn1/Asn1ObjectDescriptor.cs +++ b/crypto/src/asn1/Asn1ObjectDescriptor.cs @@ -8,6 +8,25 @@ namespace Org.BouncyCastle.Asn1 public sealed class Asn1ObjectDescriptor : Asn1Object { + internal class Meta : Asn1UniversalType + { + internal static readonly Asn1UniversalType Instance = new Meta(); + + private Meta() : base(typeof(Asn1ObjectDescriptor), Asn1Tags.ObjectDescriptor) {} + + internal override Asn1Object FromImplicitPrimitive(DerOctetString octetString) + { + return new Asn1ObjectDescriptor( + (DerGraphicString)DerGraphicString.Meta.Instance.FromImplicitPrimitive(octetString)); + } + + internal override Asn1Object FromImplicitConstructed(Asn1Sequence sequence) + { + return new Asn1ObjectDescriptor( + (DerGraphicString)DerGraphicString.Meta.Instance.FromImplicitConstructed(sequence)); + } + } + /** * Return an ObjectDescriptor from the passed in object. * @@ -31,7 +50,7 @@ namespace Org.BouncyCastle.Asn1 { try { - return GetInstance(FromByteArray((byte[])obj)); + return (Asn1ObjectDescriptor)Meta.Instance.FromByteArray((byte[])obj); } catch (IOException e) { @@ -46,21 +65,13 @@ namespace Org.BouncyCastle.Asn1 * Return an ObjectDescriptor from a tagged object. * * @param taggedObject the tagged object holding the object we want. - * @param explicit true if the object is meant to be explicitly tagged, - * false otherwise. + * @param declaredExplicit true if the object is meant to be explicitly tagged, false otherwise. * @exception IllegalArgumentException if the tagged object cannot be converted. * @return an ASN1ObjectDescriptor instance, or null. */ - public static Asn1ObjectDescriptor GetInstance(Asn1TaggedObject taggedObject, bool isExplicit) + public static Asn1ObjectDescriptor GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { - Asn1Object baseObject = taggedObject.GetObject(); - - if (isExplicit || baseObject is Asn1ObjectDescriptor) - { - return GetInstance(baseObject); - } - - return new Asn1ObjectDescriptor(new DerGraphicString(((Asn1OctetString)baseObject).GetOctets())); + return (Asn1ObjectDescriptor)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit); } private readonly DerGraphicString m_baseGraphicString; |