Skip to content

Commit 1e83a3b

Browse files
committed
[refactor] ASN.1 decode constructive impl creation
1 parent a2b4ce1 commit 1e83a3b

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
import java.lang.reflect.Method;
3636
import java.math.BigInteger;
3737
import java.text.ParseException;
38-
import java.util.Collections;
3938
import java.util.Date;
4039
import java.util.Enumeration;
4140
import java.util.HashMap;
42-
import java.util.List;
4341
import java.util.Map;
4442
import java.util.WeakHashMap;
4543

@@ -1154,26 +1152,21 @@ private BytesInputStream(final ByteList bytes) {
11541152

11551153
}
11561154

1157-
private static IRubyObject decodeImpl(final ThreadContext context,
1158-
final RubyModule ASN1, final BytesInputStream in) throws IOException, IllegalArgumentException {
1155+
private static IRubyObject decodeImpl(final ThreadContext context, final RubyModule ASN1, final BytesInputStream in)
1156+
throws IOException, IllegalArgumentException {
11591157
// NOTE: need to handle OpenSSL::ASN1::Constructive wrapping by hand :
11601158
final Integer tag = getConstructiveTag(in.bytes(), in.offset());
11611159
IRubyObject decoded = decodeObject(context, ASN1, readObject( in ));
11621160
if ( tag != null ) { // OpenSSL::ASN1::Constructive.new( arg ) :
1163-
final String type; List<IRubyObject> value = null;
11641161
if ( tag.intValue() == SEQUENCE ) {
11651162
//type = "Sequence"; // got a OpenSSL::ASN1::Sequence already :
11661163
return Constructive.setInfiniteLength(context, decoded);
11671164
}
1168-
else if ( tag.intValue() == SET ) {
1165+
if ( tag.intValue() == SET ) {
11691166
//type = "Set"; // got a OpenSSL::ASN1::Set already :
11701167
return Constructive.setInfiniteLength(context, decoded);
11711168
}
1172-
else {
1173-
type = "Constructive";
1174-
}
1175-
if ( value == null ) value = Collections.singletonList(decoded);
1176-
return Constructive.newInfiniteConstructive(context, type, value, tag);
1169+
return Constructive.newInfiniteConstructive(context, "Constructive", context.runtime.newArray(decoded), tag);
11771170
}
11781171
return decoded;
11791172
}
@@ -1744,18 +1737,14 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
17441737
}
17451738

17461739
static Constructive newInfiniteConstructive(final ThreadContext context,
1747-
final String type, final List<IRubyObject> value, final int defaultTag) {
1740+
final String type, final IRubyObject value, final int defaultTag) {
17481741
final Ruby runtime = context.runtime;
17491742

17501743
final RubyClass klass = _ASN1(context.runtime).getClass(type);
17511744
final Constructive self = new Constructive(runtime, klass);
17521745

1753-
final RubyArray values = runtime.newArray(value.size());
1754-
for ( final IRubyObject val : value ) values.append(val);
1755-
// values.append( EndOfContent.newInstance(context) );
1756-
17571746
self.setInstanceVariable("@tag", runtime.newFixnum(defaultTag));
1758-
self.setInstanceVariable("@value", values);
1747+
self.setInstanceVariable("@value", value);
17591748
self.setInstanceVariable("@tag_class", runtime.newSymbol("UNIVERSAL"));
17601749
self.setInstanceVariable("@tagging", context.nil);
17611750

0 commit comments

Comments
 (0)