Skip to content

Commit a0fb69a

Browse files
handle string in asn1data
1 parent 4a33a85 commit a0fb69a

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
@@ -1049,10 +1049,15 @@ else if ( obj instanceof ASN1GraphicString ) {
10491049
if (taggedObj.getTagClass() == BERTags.APPLICATION) {
10501050
IRubyObject tag = runtime.newFixnum( taggedObj.getTagNo() );
10511051
IRubyObject tag_class = runtime.newSymbol("APPLICATION");
1052-
final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(false, SEQUENCE);
1053-
@SuppressWarnings("unchecked")
1054-
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
1055-
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
1052+
try {
1053+
final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(false, SEQUENCE);
1054+
@SuppressWarnings("unchecked")
1055+
final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects());
1056+
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK);
1057+
} catch (IllegalStateException e) {
1058+
IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject()).callMethod(context, "value");
1059+
return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { val, tag, tag_class }, Block.NULL_BLOCK);
1060+
}
10561061
} else {
10571062
IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject());
10581063
IRubyObject tag = runtime.newFixnum( taggedObj.getTagNo() );
@@ -1380,12 +1385,13 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) {
13801385
vec.add( data );
13811386
}
13821387
return new DERTaggedObject(isExplicitTagging(), tag, new DERSequence(vec));
1388+
} else if (value instanceof ASN1Data) {
1389+
return new DERTaggedObject(isExplicitTagging(), tag, ((ASN1Data) value).toASN1(context));
1390+
} else if (value instanceof RubyObject) {
1391+
return new DERTaggedObject(isExplicitTagging(), getTagClass(context), tag, new DERGeneralString(value.asString().asJavaString()));
1392+
} else {
1393+
throw context.runtime.newTypeError("no implicit conversion of " + value.getMetaClass().getBaseName() + " into String");
13831394
}
1384-
1385-
if (!(value instanceof ASN1Data)) {
1386-
throw new UnsupportedOperationException("toASN1 " + inspect() + " value: " + value.inspect() + " (" + value.getMetaClass() + ")");
1387-
}
1388-
return new DERTaggedObject(isExplicitTagging(), tag, ((ASN1Data) value).toASN1(context));
13891395
}
13901396

13911397
@JRubyMethod

0 commit comments

Comments
 (0)