Skip to content

Commit 32608c8

Browse files
committed
Add Extensions helpers
1 parent 6fd0964 commit 32608c8

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

core/src/main/java/org/bouncycastle/asn1/x509/CertificateList.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ public Time getNextUpdate()
117117
return tbsCertList.getNextUpdate();
118118
}
119119

120+
public Extensions getExtensions()
121+
{
122+
return tbsCertList.getExtensions();
123+
}
124+
120125
public ASN1Primitive toASN1Primitive()
121126
{
122127
ASN1EncodableVector v = new ASN1EncodableVector(3);

core/src/main/java/org/bouncycastle/asn1/x509/Extensions.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.bouncycastle.asn1.ASN1EncodableVector;
99
import org.bouncycastle.asn1.ASN1Object;
1010
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
11+
import org.bouncycastle.asn1.ASN1OctetString;
1112
import org.bouncycastle.asn1.ASN1Primitive;
1213
import org.bouncycastle.asn1.ASN1Sequence;
1314
import org.bouncycastle.asn1.ASN1TaggedObject;
@@ -40,6 +41,11 @@ public static ASN1Encodable getExtensionParsedValue(Extensions extensions, ASN1O
4041
return null == extensions ? null : extensions.getExtensionParsedValue(oid);
4142
}
4243

44+
public static ASN1OctetString getExtensionValue(Extensions extensions, ASN1ObjectIdentifier oid)
45+
{
46+
return null == extensions ? null : extensions.getExtensionValue(oid);
47+
}
48+
4349
public static Extensions getInstance(
4450
ASN1TaggedObject obj,
4551
boolean explicit)
@@ -141,8 +147,7 @@ public Enumeration oids()
141147
*
142148
* @return the extension if it's present, null otherwise.
143149
*/
144-
public Extension getExtension(
145-
ASN1ObjectIdentifier oid)
150+
public Extension getExtension(ASN1ObjectIdentifier oid)
146151
{
147152
return (Extension)extensions.get(oid);
148153
}
@@ -155,14 +160,19 @@ public Extension getExtension(
155160
*/
156161
public ASN1Encodable getExtensionParsedValue(ASN1ObjectIdentifier oid)
157162
{
158-
Extension ext = this.getExtension(oid);
159-
160-
if (ext != null)
161-
{
162-
return ext.getParsedValue();
163-
}
163+
Extension ext = getExtension(oid);
164+
return ext == null ? null : ext.getParsedValue();
165+
}
164166

165-
return null;
167+
/**
168+
* return the value of the extension represented by the object identifier passed in.
169+
*
170+
* @return the value of the extension if it's present, null otherwise.
171+
*/
172+
public ASN1OctetString getExtensionValue(ASN1ObjectIdentifier oid)
173+
{
174+
Extension ext = getExtension(oid);
175+
return ext == null ? null : ext.getExtnValue();
166176
}
167177

168178
/**
@@ -229,6 +239,21 @@ public ASN1ObjectIdentifier[] getCriticalExtensionOIDs()
229239
return getExtensionOIDs(true);
230240
}
231241

242+
public boolean hasAnyCriticalExtensions()
243+
{
244+
for (int i = 0; i != ordering.size(); i++)
245+
{
246+
Object oid = ordering.elementAt(i);
247+
248+
if (((Extension)extensions.get(oid)).isCritical())
249+
{
250+
return true;
251+
}
252+
}
253+
254+
return false;
255+
}
256+
232257
private ASN1ObjectIdentifier[] getExtensionOIDs(boolean isCritical)
233258
{
234259
Vector oidVec = new Vector();

0 commit comments

Comments
 (0)