Skip to content

Commit 884bcd6

Browse files
handle string in asn1data
1 parent e192012 commit 884bcd6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

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

+15-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);
@@ -1405,12 +1410,13 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
14051410
vec.add( data );
14061411
}
14071412
return new DERTaggedObject(isExplicitTagging(), tag, new DERSequence(vec));
1413+
} else if (value instanceof ASN1Data) {
1414+
return new DERTaggedObject(isExplicitTagging(), tagClass, tag, ((ASN1Data) value).toASN1(context));
1415+
} else if (value instanceof RubyObject) {
1416+
return new DERTaggedObject(isExplicitTagging(), tagClass, tag, new DERGeneralString(value.asString().asJavaString()));
1417+
} else {
1418+
throw context.runtime.newTypeError("no implicit conversion of " + value.getMetaClass().getBaseName() + " into String");
14081419
}
1409-
1410-
if (!(value instanceof ASN1Data)) {
1411-
throw new UnsupportedOperationException("toASN1 " + inspect() + " value: " + value.inspect() + " (" + value.getMetaClass() + ")");
1412-
}
1413-
return new DERTaggedObject(isExplicitTagging(), tagClass, tag, ((ASN1Data) value).toASN1(context));
14141420
}
14151421

14161422
@JRubyMethod

0 commit comments

Comments
 (0)