aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-10-12 14:24:59 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-10-12 15:53:49 +0900
commitb99f1ddc05dbdc69fc9b79fd65d1069d96c83b86 (patch)
tree0be0c4bbb3d0c850a41dbb30e4f11642e96a4d17
parent55956cce10d7a176b71eaeada4b70adc16300146 (diff)
downloadruby-openssl-b99f1ddc05dbdc69fc9b79fd65d1069d96c83b86.tar.gz
x509attr: implement X509::Attribute#==
-rw-r--r--lib/openssl/x509.rb7
-rw-r--r--test/test_x509attr.rb17
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/openssl/x509.rb b/lib/openssl/x509.rb
index 2f87ea19..bc8ccc7d 100644
--- a/lib/openssl/x509.rb
+++ b/lib/openssl/x509.rb
@@ -165,6 +165,13 @@ module OpenSSL
end
end
+ class Attribute
+ def ==(other)
+ return false unless Attribute === other
+ to_der == other.to_der
+ end
+ end
+
class StoreContext
def cleanup
warn "(#{caller.first}) OpenSSL::X509::StoreContext#cleanup is deprecated with no replacement" if $VERBOSE
diff --git a/test/test_x509attr.rb b/test/test_x509attr.rb
index 108162f4..c6c48e86 100644
--- a/test/test_x509attr.rb
+++ b/test/test_x509attr.rb
@@ -62,6 +62,23 @@ class OpenSSL::TestX509Attribute < OpenSSL::TestCase
attr = OpenSSL::X509::Attribute.new("challengePassword", val)
assert_equal(attr.to_der, attr.dup.to_der)
end
+
+ def test_eq
+ val1 = OpenSSL::ASN1::Set([
+ OpenSSL::ASN1::UTF8String("abc123")
+ ])
+ attr1 = OpenSSL::X509::Attribute.new("challengePassword", val1)
+ attr2 = OpenSSL::X509::Attribute.new("challengePassword", val1)
+ ef = OpenSSL::X509::ExtensionFactory.new
+ val2 = OpenSSL::ASN1::Set.new([OpenSSL::ASN1::Sequence.new([
+ ef.create_extension("keyUsage", "keyCertSign", true)
+ ])])
+ attr3 = OpenSSL::X509::Attribute.new("extReq", val2)
+
+ assert_equal false, attr1 == 12345
+ assert_equal true, attr1 == attr2
+ assert_equal false, attr1 == attr3
+ end
end
end