Skip to content

Commit 4fc041f

Browse files
committed
Add ASN1TaggedObject getOptional methods
1 parent dcdbca5 commit 4fc041f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

core/src/main/java/org/bouncycastle/asn1/ASN1TaggedObject.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,41 @@ public static ASN1TaggedObject getInstance(ASN1TaggedObject taggedObject, int ta
7575
return ASN1Util.getExplicitBaseTagged(checkInstance(taggedObject, declaredExplicit), tagClass, tagNo);
7676
}
7777

78+
public static ASN1TaggedObject getOptional(ASN1Object element)
79+
{
80+
if (element == null)
81+
{
82+
throw new NullPointerException("'element' cannot be null");
83+
}
84+
85+
if (element instanceof ASN1TaggedObject)
86+
{
87+
return (ASN1TaggedObject)element;
88+
}
89+
90+
return null;
91+
}
92+
93+
public static ASN1TaggedObject getOptional(ASN1Object element, int tagClass)
94+
{
95+
ASN1TaggedObject taggedObject = getOptional(element);
96+
if (taggedObject != null && taggedObject.hasTagClass(tagClass))
97+
{
98+
return taggedObject;
99+
}
100+
return null;
101+
}
102+
103+
public static ASN1TaggedObject getOptional(ASN1Object element, int tagClass, int tagNo)
104+
{
105+
ASN1TaggedObject taggedObject = getOptional(element);
106+
if (taggedObject != null && taggedObject.hasTag(tagClass, tagNo))
107+
{
108+
return taggedObject;
109+
}
110+
return null;
111+
}
112+
78113
private static ASN1TaggedObject checkInstance(Object obj)
79114
{
80115
if (obj == null)

0 commit comments

Comments
 (0)