Skip to content

Commit 4daed8e

Browse files
fixed logic around error parsing oid
it's supposed to raise on der encoding (not initialization), and it's supposed to be an ASN1Error (not TypeError) exception
1 parent 2585b09 commit 4daed8e

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -739,26 +739,19 @@ public static void createASN1(final Ruby runtime, final RubyModule OpenSSL, fina
739739
}
740740

741741
static ASN1ObjectIdentifier getObjectID(final Ruby runtime, final String nameOrOid)
742-
throws IllegalArgumentException {
742+
throws RaiseException {
743743
final String name = nameOrOid.toLowerCase();
744744

745745
ASN1ObjectIdentifier objectId = getOIDLookup(runtime).get( name );
746746
if ( objectId != null ) return objectId;
747747

748748
final String objectIdStr = ASN1Registry.getOIDLookup().get( name );
749-
if ( objectIdStr != null ) return toObjectID(objectIdStr, false);
749+
if ( objectIdStr != null ) return new ASN1ObjectIdentifier(objectIdStr);
750750

751-
return new ASN1ObjectIdentifier( nameOrOid );
752-
}
753-
754-
static ASN1ObjectIdentifier toObjectID(final String oid, final boolean silent)
755-
throws IllegalArgumentException {
756751
try {
757-
return new ASN1ObjectIdentifier(oid);
758-
}
759-
catch (IllegalArgumentException e) {
760-
if ( silent ) return null;
761-
throw e;
752+
return new ASN1ObjectIdentifier( nameOrOid );
753+
} catch (IllegalArgumentException e) {
754+
throw newASN1Error(runtime, "invalid OBJECT ID " + nameOrOid + ": " + e.getMessage());
762755
}
763756
}
764757

@@ -1776,17 +1769,6 @@ static void initializeImpl(final ThreadContext context,
17761769
// NOTE: Primitive only
17771770
final String baseName = self.getMetaClass().getRealClass().getBaseName();
17781771
switch (baseName) {
1779-
case "ObjectId":
1780-
final String name;
1781-
try {
1782-
name = oid2Sym( runtime, getObjectID(runtime, value.toString()), true );
1783-
}
1784-
catch (IllegalArgumentException e) {
1785-
// e.g. in case of nil "string not an OID"
1786-
throw runtime.newTypeError(e.getMessage());
1787-
}
1788-
if ( name != null ) value = runtime.newString(name);
1789-
break;
17901772
case "BitString":
17911773
self.setInstanceVariable("@unused_bits", runtime.newFixnum(0));
17921774
break;
@@ -1858,7 +1840,9 @@ private ASN1Encodable toASN1Primitive(final ThreadContext context) {
18581840

18591841
final IRubyObject val = value(context);
18601842
if ( type == ASN1ObjectIdentifier.class ) {
1861-
return getObjectID(context.runtime, val.toString());
1843+
final String oidStr = val.convertToString().toString();
1844+
1845+
return getObjectID(context.runtime, oidStr);
18621846
}
18631847
if ( type == DERNull.class || type == ASN1Null.class ) {
18641848
return DERNull.INSTANCE;

0 commit comments

Comments
 (0)