Skip to content

Commit

Permalink
[fix] missing OpenSSL::ASN1::ObjectId#== (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Dec 13, 2024
1 parent d692376 commit 976a3f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/jruby/ext/openssl/ASN1.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,14 @@ public static RubyString oid(final ThreadContext context, final IRubyObject self
return runtime.newString( getObjectID(runtime, self.callMethod(context, "value").toString()).getId() );
}

@JRubyMethod(name = "==")
public static IRubyObject eq(final ThreadContext context, final IRubyObject self, final IRubyObject other) {
if (!other.getMetaClass().equals(_ASN1(context.runtime).getClass("ObjectId"))) {
return context.runtime.getFalse();
}
return self.callMethod(context, "value").op_eqq(context, other.callMethod(context, "value"));
}

private static RubyString name(final ThreadContext context, IRubyObject value,
final boolean longName) {
final Ruby runtime = context.runtime;
Expand Down
4 changes: 4 additions & 0 deletions src/test/ruby/test_asn1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ def test_object_identifier
#assert_raise(TypeError) {
# OpenSSL::ASN1::ObjectId.new("authorityKeyIdentifier") == nil
#}

oid = OpenSSL::ASN1::ObjectId.new("2.5.29.14")
assert_equal true, oid == OpenSSL::ASN1::ObjectId.new("2.5.29.14")
assert_equal false, oid == OpenSSL::ASN1::ObjectId.new("2.5.29.35")
end

def test_instantiate
Expand Down

0 comments on commit 976a3f5

Please sign in to comment.