Skip to content

Commit

Permalink
[refactor] simplify & use i-var for consistency; tagClass getter
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed May 5, 2024
1 parent c3db400 commit eae9f56
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,20 @@ boolean isEOC() {
boolean isImplicitTagging() { return true; }

int getTag(final ThreadContext context) {
return RubyNumeric.fix2int(callMethod(context, "tag"));
return RubyNumeric.fix2int(getInstanceVariable("@tag"));
}

int getTagClass(final ThreadContext context) {
IRubyObject tag_class = getInstanceVariable("@tag_class");
if (tag_class instanceof RubySymbol) {
if ("APPLICATION".equals(tag_class.toString())) {
return BERTags.APPLICATION;
}
if ("CONTEXT_SPECIFIC".equals(tag_class.toString())) {
return BERTags.CONTEXT_SPECIFIC;
}
}
return BERTags.UNIVERSAL; // 0
}

ASN1Encodable toASN1(final ThreadContext context) {
Expand Down Expand Up @@ -1775,8 +1788,7 @@ private boolean isInfiniteLength() {
@Override
boolean isExplicitTagging() {
IRubyObject tagging = getInstanceVariable("@tagging");
if ( tagging.isNil() ) return true;
return "EXPLICIT".equals( tagging.toString() );
return tagging.isNil() || "EXPLICIT".equals( tagging.toString() );
}

@Override
Expand Down Expand Up @@ -1830,22 +1842,21 @@ byte[] toDER(final ThreadContext context) throws IOException {
if ( isSequence() ) {
return sequenceToDER(context);
}
else if ( isSet() ) {
if ( isSet() ) {
return setToDER(context);
}
else { // "raw" Constructive
switch ( getTag(context) ) {
case OCTET_STRING:
return octetStringToDER(context);
case BIT_STRING:
return bitStringToDER(context);
case SEQUENCE:
return sequenceToDER(context);
case SET:
return setToDER(context);
}
throw new UnsupportedOperationException( this.inspect().toString() );
// "raw" Constructive
switch ( getTag(context) ) {
case OCTET_STRING:
return octetStringToDER(context);
case BIT_STRING:
return bitStringToDER(context);
case SEQUENCE:
return sequenceToDER(context);
case SET:
return setToDER(context);
}
throw new UnsupportedOperationException( this.inspect().toString() );
}

return super.toDER(context);
Expand Down

0 comments on commit eae9f56

Please sign in to comment.