diff options
Diffstat (limited to 'crypto/src/asn1/Asn1Utilities.cs')
-rw-r--r-- | crypto/src/asn1/Asn1Utilities.cs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/crypto/src/asn1/Asn1Utilities.cs b/crypto/src/asn1/Asn1Utilities.cs index dca2253ec..fe6db2df7 100644 --- a/crypto/src/asn1/Asn1Utilities.cs +++ b/crypto/src/asn1/Asn1Utilities.cs @@ -23,5 +23,74 @@ namespace Org.BouncyCastle.Asn1 return "[UNIVERSAL " + tagNo + "]"; } } + + /* + * Wrappers for Asn1TaggedObject.GetExplicitBaseObject + */ + + public static Asn1Encodable GetExplicitBaseObject(Asn1TaggedObject taggedObject, int tagClass, int tagNo) + { + if (!taggedObject.HasTag(tagClass, tagNo)) + { + string expected = GetTagText(tagClass, tagNo); + string found = GetTagText(taggedObject); + throw new InvalidOperationException("Expected " + expected + " tag but found " + found); + } + + return taggedObject.GetExplicitBaseObject(); + } + + public static Asn1Encodable GetExplicitContextBaseObject(Asn1TaggedObject taggedObject, int tagNo) + { + return GetExplicitBaseObject(taggedObject, Asn1Tags.ContextSpecific, tagNo); + } + + public static Asn1Encodable TryGetExplicitBaseObject(Asn1TaggedObject taggedObject, int tagClass, int tagNo) + { + if (!taggedObject.HasTag(tagClass, tagNo)) + return null; + + return taggedObject.GetExplicitBaseObject(); + } + + public static Asn1Encodable TryGetExplicitContextBaseObject(Asn1TaggedObject taggedObject, int tagNo) + { + return TryGetExplicitBaseObject(taggedObject, Asn1Tags.ContextSpecific, tagNo); + } + + + /* + * Wrappers for Asn1TaggedObject.GetExplicitBaseTagged + */ + + public static Asn1TaggedObject GetExplicitBaseTagged(Asn1TaggedObject taggedObject, int tagClass, int tagNo) + { + if (!taggedObject.HasTag(tagClass, tagNo)) + { + string expected = GetTagText(tagClass, tagNo); + string found = GetTagText(taggedObject); + throw new InvalidOperationException("Expected " + expected + " tag but found " + found); + } + + return taggedObject.GetExplicitBaseTagged(); + } + + public static Asn1TaggedObject GetExplicitContextBaseTagged(Asn1TaggedObject taggedObject, int tagNo) + { + return GetExplicitBaseTagged(taggedObject, Asn1Tags.ContextSpecific, tagNo); + } + + public static Asn1TaggedObject TryGetExplicitBaseTagged(Asn1TaggedObject taggedObject, int tagClass, int tagNo) + { + if (!taggedObject.HasTag(tagClass, tagNo)) + return null; + + return taggedObject.GetExplicitBaseTagged(); + } + + public static Asn1TaggedObject TryGetExplicitContextBaseTagged(Asn1TaggedObject taggedObject, int tagNo) + { + return TryGetExplicitBaseTagged(taggedObject, Asn1Tags.ContextSpecific, tagNo); + } } } |