diff --git a/src/main/java/org/jruby/ext/openssl/ASN1.java b/src/main/java/org/jruby/ext/openssl/ASN1.java index 0dd7e337..8d579492 100644 --- a/src/main/java/org/jruby/ext/openssl/ASN1.java +++ b/src/main/java/org/jruby/ext/openssl/ASN1.java @@ -1064,10 +1064,15 @@ else if ( obj instanceof ASN1GraphicString ) { } if (taggedObj.getTagClass() == BERTags.APPLICATION) { - final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(false, SEQUENCE); - @SuppressWarnings("unchecked") - final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects()); - return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK); + try { + final ASN1Sequence sequence = (ASN1Sequence) taggedObj.getBaseUniversal(false, SEQUENCE); + @SuppressWarnings("unchecked") + final RubyArray valArr = decodeObjects(context, ASN1, sequence.getObjects()); + return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { valArr, tag, tag_class }, Block.NULL_BLOCK); + } catch (IllegalStateException e) { + IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject()).callMethod(context, "value"); + return ASN1.getClass("ASN1Data").newInstance(context, new IRubyObject[] { val, tag, tag_class }, Block.NULL_BLOCK); + } } else { IRubyObject val = decodeObject(context, ASN1, taggedObj.getBaseObject()); final RubyArray valArr = runtime.newArray(val); @@ -1397,12 +1402,13 @@ final ASN1TaggedObject toASN1TaggedObject(final ThreadContext context) { vec.add( data ); } return new DERTaggedObject(isExplicitTagging(), tag, new DERSequence(vec)); + } else if (value instanceof ASN1Data) { + return new DERTaggedObject(isExplicitTagging(), tagClass, tag, ((ASN1Data) value).toASN1(context)); + } else if (value instanceof RubyObject) { + return new DERTaggedObject(isExplicitTagging(), tagClass, tag, new DERGeneralString(value.asString().asJavaString())); + } else { + throw context.runtime.newTypeError("no implicit conversion of " + value.getMetaClass().getBaseName() + " into String"); } - - if (!(value instanceof ASN1Data)) { - throw new UnsupportedOperationException("toASN1 " + inspect() + " value: " + value.inspect() + " (" + value.getMetaClass() + ")"); - } - return new DERTaggedObject(isExplicitTagging(), tagClass, tag, ((ASN1Data) value).toASN1(context)); } @JRubyMethod