Skip to content

Commit 28d3c44

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 e40b37a commit 28d3c44

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

@@ -1784,17 +1777,6 @@ static void initializeImpl(final ThreadContext context,
17841777
// NOTE: Primitive only
17851778
final String baseName = self.getMetaClass().getRealClass().getBaseName();
17861779
switch (baseName) {
1787-
case "ObjectId":
1788-
final String name;
1789-
try {
1790-
name = oid2Sym( runtime, getObjectID(runtime, value.toString()), true );
1791-
}
1792-
catch (IllegalArgumentException e) {
1793-
// e.g. in case of nil "string not an OID"
1794-
throw runtime.newTypeError(e.getMessage());
1795-
}
1796-
if ( name != null ) value = runtime.newString(name);
1797-
break;
17981780
case "BitString":
17991781
self.setInstanceVariable("@unused_bits", runtime.newFixnum(0));
18001782
break;
@@ -1866,7 +1848,9 @@ private ASN1Encodable toASN1Primitive(final ThreadContext context) {
18661848

18671849
final IRubyObject val = value(context);
18681850
if ( type == ASN1ObjectIdentifier.class ) {
1869-
return getObjectID(context.runtime, val.toString());
1851+
final String oidStr = val.convertToString().toString();
1852+
1853+
return getObjectID(context.runtime, oidStr);
18701854
}
18711855
if ( type == DERNull.class || type == ASN1Null.class ) {
18721856
return DERNull.INSTANCE;

0 commit comments

Comments
 (0)