diff options
author | Peter Dettman <peter.dettman@gmail.com> | 2022-06-22 15:53:05 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@gmail.com> | 2022-06-22 15:53:05 +0700 |
commit | 932e31ba9920344c228314e665cb80c62eb17761 (patch) | |
tree | 7a6862d7bf0952227e6071c94f4f6806a4373134 /crypto/src/asn1 | |
parent | ObsoleteAttribute cleanup (diff) | |
download | BouncyCastle.NET-ed25519-932e31ba9920344c228314e665cb80c62eb17761.tar.xz |
Add utility methods
Diffstat (limited to 'crypto/src/asn1')
-rw-r--r-- | crypto/src/asn1/Asn1TaggedObject.cs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/crypto/src/asn1/Asn1TaggedObject.cs b/crypto/src/asn1/Asn1TaggedObject.cs index f2bf0cfe1..82fe0913c 100644 --- a/crypto/src/asn1/Asn1TaggedObject.cs +++ b/crypto/src/asn1/Asn1TaggedObject.cs @@ -47,6 +47,30 @@ namespace Org.BouncyCastle.Asn1 throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj), "obj"); } + public static Asn1TaggedObject GetInstance(object obj, int tagClass) + { + if (obj == null) + throw new ArgumentNullException(nameof(obj)); + + Asn1TaggedObject taggedObject = GetInstance(obj); + if (tagClass != taggedObject.TagClass) + throw new ArgumentException("unexpected tag in GetInstance: " + Asn1Utilities.GetTagText(taggedObject)); + + return taggedObject; + } + + public static Asn1TaggedObject GetInstance(Object obj, int tagClass, int tagNo) + { + if (obj == null) + throw new ArgumentNullException(nameof(obj)); + + Asn1TaggedObject taggedObject = GetInstance(obj); + if (!taggedObject.HasTag(tagClass, tagNo)) + throw new ArgumentException("unexpected tag in GetInstance: " + Asn1Utilities.GetTagText(taggedObject)); + + return taggedObject; + } + public static Asn1TaggedObject GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { if (Asn1Tags.ContextSpecific != taggedObject.TagClass) |