Skip to content

Commit aa03671

Browse files
handle string in asn1data
1 parent 4c57f18 commit aa03671

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Diff for: src/main/java/org/jruby/ext/openssl/ASN1.java

+15-9
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,15 @@ else if ( obj instanceof ASN1GraphicString ) {
10641064
}
10651065

10661066
if (taggedObj.getTagClass() == BERTags.APPLICATION) {
1067-
final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(false, SEQUENCE);
1068-
@SuppressWarnings("unchecked")
1069-
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
1070-
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
1067+
try {
1068+
final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(false, SEQUENCE);
1069+
@SuppressWarnings("unchecked")
1070+
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
1071+
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
1072+
} catch (IllegalStateException e) {
1073+
IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject()).callMethod(context, "value");
1074+
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { val, tag, tag_class }, Block.NULL_BLOCK);
1075+
}
10711076
} else {
10721077
IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject());
10731078
final RubyArray valArr = runtime.newArray(val);
@@ -1397,12 +1402,13 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
13971402
vec.add( data );
13981403
}
13991404
return new DERTaggedObject(isExplicitTagging(), tag, new DERSequence(vec));
1405+
} else if (value instanceof ASN1Data) {
1406+
return new DERTaggedObject(isExplicitTagging(), tagClass, tag, ((ASN1Data) value).toASN1(context));
1407+
} else if (value instanceof RubyObject) {
1408+
return new DERTaggedObject(isExplicitTagging(), tagClass, tag, new DERGeneralString(value.asString().asJavaString()));
1409+
} else {
1410+
throw context.runtime.newTypeError("no implicit conversion of " + value.getMetaClass().getBaseName() + " into String");
14001411
}
1401-
1402-
if (!(value instanceof ASN1Data)) {
1403-
throw new UnsupportedOperationException("toASN1 " + inspect() + " value: " + value.inspect() + " (" + value.getMetaClass() + ")");
1404-
}
1405-
return new DERTaggedObject(isExplicitTagging(), tagClass, tag, ((ASN1Data) value).toASN1(context));
14061412
}
14071413

14081414
@JRubyMethod

0 commit comments

Comments
 (0)