diff --git a/src/main/java/org/jruby/ext/openssl/ASN1.java b/src/main/java/org/jruby/ext/openssl/ASN1.java index 2444d9e9..37a109f4 100644 --- a/src/main/java/org/jruby/ext/openssl/ASN1.java +++ b/src/main/java/org/jruby/ext/openssl/ASN1.java @@ -1049,10 +1049,15 @@ else if ( obj instanceof ASN1GraphicString ) { if (taggedObj.getTagClass() == BERTags.APPLICATION) { IRubyObject tag = runtime.newFixnum( taggedObj.getTagNo() ); IRubyObject tag_class = runtime.newSymbol("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()); IRubyObject tag = runtime.newFixnum( taggedObj.getTagNo() ); @@ -1380,12 +1385,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(), tag, ((ASN1Data) value).toASN1(context)); + } else if (value instanceof RubyObject) { + return new DERTaggedObject(isExplicitTagging(), getTagClass(context), 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(), tag, ((ASN1Data) value).toASN1(context)); } @JRubyMethod