aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-10-12 14:29:32 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-10-12 15:53:49 +0900
commit55956cce10d7a176b71eaeada4b70adc16300146 (patch)
tree73f0b906f98943b9f2c3f99fd2513c38c60d2f24
parente72d960db2623b21ee001b5a7b9d9e6ff55bdf94 (diff)
downloadruby-openssl-55956cce10d7a176b71eaeada4b70adc16300146.tar.gz
x509ext: implement X509::Extension#==
-rw-r--r--lib/openssl/x509.rb5
-rw-r--r--test/test_x509ext.rb11
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/openssl/x509.rb b/lib/openssl/x509.rb
index 6d31b98c..2f87ea19 100644
--- a/lib/openssl/x509.rb
+++ b/lib/openssl/x509.rb
@@ -41,6 +41,11 @@ module OpenSSL
end
class Extension
+ def ==(other)
+ return false unless Extension === other
+ to_der == other.to_der
+ end
+
def to_s # "oid = critical, value"
str = self.oid
str << " = "
diff --git a/test/test_x509ext.rb b/test/test_x509ext.rb
index f384a25e..91ce202f 100644
--- a/test/test_x509ext.rb
+++ b/test/test_x509ext.rb
@@ -75,6 +75,17 @@ class OpenSSL::TestX509Extension < OpenSSL::TestCase
assert_equal(@basic_constraints.to_der, ext.to_der)
assert_equal(ext.to_der, ext.dup.to_der)
end
+
+ def test_eq
+ ext1 = OpenSSL::X509::Extension.new(@basic_constraints.to_der)
+ ef = OpenSSL::X509::ExtensionFactory.new
+ ext2 = ef.create_extension("basicConstraints", "critical, CA:TRUE, pathlen:2")
+ ext3 = ef.create_extension("basicConstraints", "critical, CA:TRUE")
+
+ assert_equal false, ext1 == 12345
+ assert_equal true, ext1 == ext2
+ assert_equal false, ext1 == ext3
+ end
end
end