Skip to content

Commit f76c475

Browse files
committed
[refactor] due BC 1.77 which does not allow empty Extensions
1 parent 840a1fa commit f76c475

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/main/java/org/jruby/ext/openssl/OCSPBasicResponse.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,12 @@ public IRubyObject sign(final ThreadContext context, IRubyObject[] args) {
350350
}
351351

352352
try {
353-
Extension[] respExtAry = new Extension[extensions.size()];
354-
Extensions respExtensions = new Extensions(extensions.toArray(respExtAry));
353+
final Extensions respExtensions;
354+
if (extensions != null && extensions.size() > 0) {
355+
respExtensions = new Extensions(extensions.toArray(new Extension[extensions.size()]));
356+
} else {
357+
respExtensions = null;
358+
}
355359
BasicOCSPResp bcBasicOCSPResp = respBuilder.setResponseExtensions(respExtensions).build(contentSigner, chain, producedAt);
356360
asn1BCBasicOCSPResp = BasicOCSPResponse.getInstance(bcBasicOCSPResp.getEncoded());
357361
}
@@ -586,22 +590,21 @@ else if (intOrTime instanceof RubyTime) {
586590
return new ASN1GeneralizedTime(retTime);
587591
}
588592

589-
private Extensions convertRubyExtensions(IRubyObject extensions) {
590-
if (extensions.isNil()) return null;
591-
List<Extension> retExtensions = new ArrayList<Extension>();
592-
Iterator<IRubyObject> rubyExtensions = ((RubyArray)extensions).iterator();
593-
while (rubyExtensions.hasNext()) {
594-
X509Extension rubyExt = (X509Extension)rubyExtensions.next();
595-
Extension ext = Extension.getInstance(((RubyString)rubyExt.to_der()).getBytes());
596-
retExtensions.add(ext);
597-
}
598-
Extension[] exts = new Extension[retExtensions.size()];
599-
retExtensions.toArray(exts);
600-
return new Extensions(exts);
593+
private Extensions convertRubyExtensions(final IRubyObject arg) {
594+
if (arg.isNil()) return null;
595+
final RubyArray rubyExts = arg.convertToArray(); // Array<X509Extension>
596+
if (rubyExts.isEmpty()) return null;
597+
598+
final Extension[] extensions = new Extension[rubyExts.size()];
599+
for (int i = 0; i<extensions.length; i++) {
600+
X509Extension rubyExt = (X509Extension) rubyExts.eltInternal(i);
601+
extensions[i] = Extension.getInstance((rubyExt.to_der()).getBytes());
602+
}
603+
return new Extensions(extensions);
601604
}
602605

603606
private List<java.security.cert.Certificate> convertRubyCerts(IRubyObject certificates) {
604-
Iterator<java.security.cert.Certificate> it = ((RubyArray)certificates).iterator();
607+
Iterator<java.security.cert.Certificate> it = certificates.convertToArray().iterator();
605608
List<java.security.cert.Certificate> ret = new ArrayList<java.security.cert.Certificate>();
606609
while (it.hasNext()) {
607610
ret.add(it.next());

src/main/java/org/jruby/ext/openssl/X509Extension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public IRubyObject set_critical(final ThreadContext context, IRubyObject arg) {
799799
}
800800

801801
@JRubyMethod
802-
public IRubyObject to_der() {
802+
public RubyString to_der() {
803803
try {
804804
return StringHelper.newString(getRuntime(), toDER());
805805
}

0 commit comments

Comments
 (0)