Skip to content

Commit

Permalink
[refactor] due BC 1.77 which does not allow empty Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Apr 20, 2024
1 parent 840a1fa commit f76c475
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
33 changes: 18 additions & 15 deletions src/main/java/org/jruby/ext/openssl/OCSPBasicResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,12 @@ public IRubyObject sign(final ThreadContext context, IRubyObject[] args) {
}

try {
Extension[] respExtAry = new Extension[extensions.size()];
Extensions respExtensions = new Extensions(extensions.toArray(respExtAry));
final Extensions respExtensions;
if (extensions != null && extensions.size() > 0) {
respExtensions = new Extensions(extensions.toArray(new Extension[extensions.size()]));
} else {
respExtensions = null;
}
BasicOCSPResp bcBasicOCSPResp = respBuilder.setResponseExtensions(respExtensions).build(contentSigner, chain, producedAt);
asn1BCBasicOCSPResp = BasicOCSPResponse.getInstance(bcBasicOCSPResp.getEncoded());
}
Expand Down Expand Up @@ -586,22 +590,21 @@ else if (intOrTime instanceof RubyTime) {
return new ASN1GeneralizedTime(retTime);
}

private Extensions convertRubyExtensions(IRubyObject extensions) {
if (extensions.isNil()) return null;
List<Extension> retExtensions = new ArrayList<Extension>();
Iterator<IRubyObject> rubyExtensions = ((RubyArray)extensions).iterator();
while (rubyExtensions.hasNext()) {
X509Extension rubyExt = (X509Extension)rubyExtensions.next();
Extension ext = Extension.getInstance(((RubyString)rubyExt.to_der()).getBytes());
retExtensions.add(ext);
}
Extension[] exts = new Extension[retExtensions.size()];
retExtensions.toArray(exts);
return new Extensions(exts);
private Extensions convertRubyExtensions(final IRubyObject arg) {
if (arg.isNil()) return null;
final RubyArray rubyExts = arg.convertToArray(); // Array<X509Extension>
if (rubyExts.isEmpty()) return null;

final Extension[] extensions = new Extension[rubyExts.size()];
for (int i = 0; i<extensions.length; i++) {
X509Extension rubyExt = (X509Extension) rubyExts.eltInternal(i);
extensions[i] = Extension.getInstance((rubyExt.to_der()).getBytes());
}
return new Extensions(extensions);
}

private List<java.security.cert.Certificate> convertRubyCerts(IRubyObject certificates) {
Iterator<java.security.cert.Certificate> it = ((RubyArray)certificates).iterator();
Iterator<java.security.cert.Certificate> it = certificates.convertToArray().iterator();
List<java.security.cert.Certificate> ret = new ArrayList<java.security.cert.Certificate>();
while (it.hasNext()) {
ret.add(it.next());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jruby/ext/openssl/X509Extension.java
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ public IRubyObject set_critical(final ThreadContext context, IRubyObject arg) {
}

@JRubyMethod
public IRubyObject to_der() {
public RubyString to_der() {
try {
return StringHelper.newString(getRuntime(), toDER());
}
Expand Down

0 comments on commit f76c475

Please sign in to comment.