diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-10-12 14:10:19 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-10-12 15:53:49 +0900 |
commit | 432a9f3455f537a99fe9771e550d0e3a682e99e8 (patch) | |
tree | acd0ad414acae491a8ee07bcc418c64d94d4cc7c /ext/openssl | |
parent | b99f1ddc05dbdc69fc9b79fd65d1069d96c83b86 (diff) | |
download | ruby-openssl-432a9f3455f537a99fe9771e550d0e3a682e99e8.tar.gz |
x509cert: implement X509::Certificate#==
Diffstat (limited to 'ext/openssl')
-rw-r--r-- | ext/openssl/ossl_x509cert.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ext/openssl/ossl_x509cert.c b/ext/openssl/ossl_x509cert.c index 003a9c19..cf82a53d 100644 --- a/ext/openssl/ossl_x509cert.c +++ b/ext/openssl/ossl_x509cert.c @@ -684,6 +684,26 @@ ossl_x509_inspect(VALUE self) } /* + * call-seq: + * cert1 == cert2 -> true | false + * + * Compares the two certificates. Note that this takes into account all fields, + * not just the issuer name and the serial number. + */ +static VALUE +ossl_x509_eq(VALUE self, VALUE other) +{ + X509 *a, *b; + + GetX509(self, a); + if (!rb_obj_is_kind_of(other, cX509Cert)) + return Qfalse; + GetX509(other, b); + + return !X509_cmp(a, b) ? Qtrue : Qfalse; +} + +/* * INIT */ void @@ -821,4 +841,5 @@ Init_ossl_x509cert(void) rb_define_method(cX509Cert, "extensions=", ossl_x509_set_extensions, 1); rb_define_method(cX509Cert, "add_extension", ossl_x509_add_extension, 1); rb_define_method(cX509Cert, "inspect", ossl_x509_inspect, 0); + rb_define_method(cX509Cert, "==", ossl_x509_eq, 1); } |