Skip to content

Commit

Permalink
handle string in asn1data
Browse files Browse the repository at this point in the history
  • Loading branch information
HoneyryderChuck committed May 10, 2024
1 parent 4a33a85 commit a0fb69a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0fb69a

Please sign in to comment.