Skip to content

Commit ac7a9d4

Browse files
handle string in asn1data
1 parent 7be1d05 commit ac7a9d4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,15 @@ else if ( obj instanceof ASN1GraphicString ) {
10721072
}
10731073

10741074
if (taggedObj.getTagClass() == BERTags.APPLICATION) {
1075-
final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(false, SEQUENCE);
1076-
@SuppressWarnings("unchecked")
1077-
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
1078-
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
1075+
try {
1076+
final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(false, SEQUENCE);
1077+
@SuppressWarnings("unchecked")
1078+
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
1079+
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
1080+
} catch (IllegalStateException e) {
1081+
IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject()).callMethod(context, "value");
1082+
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { val, tag, tag_class }, Block.NULL_BLOCK);
1083+
}
10791084
} else {
10801085
IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject());
10811086
final RubyArray valArr = runtime.newArray(val);
@@ -1444,11 +1449,6 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
14441449
throw context.runtime.newTypeError(
14451450
"no implicit conversion of " + value.getMetaClass().getBaseName() + " into String");
14461451
}
1447-
1448-
if (!(value instanceof ASN1Data)) {
1449-
throw new UnsupportedOperationException("toASN1 " + inspect() + " value: " + value.inspect() + " (" + value.getMetaClass() + ")");
1450-
}
1451-
return new DERTaggedObject(isExplicitTagging(), tagClass, tag, ((ASN1Data) value).toASN1(context));
14521452
}
14531453

14541454
@JRubyMethod

0 commit comments

Comments
 (0)