Skip to content

Commit 8007fc1

Browse files
committed
[refactor] use ASN1 base class instance checks
1 parent 1e83a3b commit 8007fc1

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/main/java/org/jruby/ext/openssl/ASN1.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,8 @@ static IRubyObject decodeObject(final ThreadContext context,
963963
return ASN1.getClass("Integer").newInstance(context, val, Block.NULL_BLOCK);
964964
}
965965

966-
if ( obj instanceof DERBitString ) {
967-
final DERBitString derObj = (DERBitString) obj;
966+
if ( obj instanceof ASN1BitString ) {
967+
final ASN1BitString derObj = (ASN1BitString) obj;
968968
RubyString str = runtime.newString( new ByteList(derObj.getBytes(), false) );
969969
IRubyObject bitString = ASN1.getClass("BitString").newInstance(context, str, Block.NULL_BLOCK);
970970
bitString.callMethod(context, "unused_bits=", runtime.newFixnum( derObj.getPadBits() ));
@@ -974,31 +974,31 @@ static IRubyObject decodeObject(final ThreadContext context,
974974
final Integer typeId = typeId( obj.getClass() );
975975
String type = typeId == null ? null : (String) ( ASN1_INFO[typeId][2] );
976976
final ByteList bytes;
977-
if ( obj instanceof DERUTF8String ) {
977+
if ( obj instanceof ASN1UTF8String ) {
978978
if ( type == null ) type = "UTF8String";
979-
bytes = new ByteList(((DERUTF8String) obj).getString().getBytes("UTF-8"), false);
979+
bytes = new ByteList(((ASN1UTF8String) obj).getString().getBytes("UTF-8"), false);
980980
}
981981
else {
982982
if ( type == null ) {
983-
if ( obj instanceof DERNumericString ) {
983+
if ( obj instanceof ASN1NumericString ) {
984984
type = "NumericString";
985985
}
986-
else if ( obj instanceof DERPrintableString ) {
986+
else if ( obj instanceof ASN1PrintableString ) {
987987
type = "PrintableString";
988988
}
989-
else if ( obj instanceof DERIA5String ) {
989+
else if ( obj instanceof ASN1IA5String ) {
990990
type = "IA5String";
991991
}
992-
else if ( obj instanceof DERT61String ) {
992+
else if ( obj instanceof ASN1T61String ) {
993993
type = "T61String";
994994
}
995-
else if ( obj instanceof DERGeneralString ) {
995+
else if ( obj instanceof ASN1GeneralString ) {
996996
type = "GeneralString";
997997
}
998-
else if ( obj instanceof DERUniversalString ) {
998+
else if ( obj instanceof ASN1UniversalString ) {
999999
type = "UniversalString";
10001000
}
1001-
else if ( obj instanceof DERBMPString ) {
1001+
else if ( obj instanceof ASN1BMPString ) {
10021002
type = "BMPString";
10031003
}
10041004
else {
@@ -1011,11 +1011,6 @@ else if ( obj instanceof DERBMPString ) {
10111011
return ASN1.getClass(type).newInstance(context, runtime.newString(bytes), Block.NULL_BLOCK);
10121012
}
10131013

1014-
//if ( obj instanceof DEROctetString ) {
1015-
// byte[] octets = ((ASN1OctetString) obj).getOctets();
1016-
// if ( (octets[0] & 0xFF) == 0xD1 ) Thread.dumpStack();
1017-
//}
1018-
10191014
if ( obj instanceof ASN1OctetString ) {
10201015
final ByteList octets = new ByteList(((ASN1OctetString) obj).getOctets(), false);
10211016
// NOTE: sometimes MRI does include the tag but it really should not ;( !

0 commit comments

Comments
 (0)