summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2020-08-08 23:00:10 +0900
committerKazuki Yamaguchi <k@rhe.jp>2021-03-16 19:16:11 +0900
commitbe3ba2ee4d4104a36a6dc2a15f16522454db33ae (patch)
tree049402008540b4d6744d71e2cf17a7033bd206db
parent08c99a4208af1a50e0ee2446ad4bb235edea00e5 (diff)
[ruby/openssl] x509store: refactor X509::StoreContext#chain
Use ossl_x509_sk2ary() to create an array of OpenSSL::X509::Certificate from STACK_OF(X509). https://github.com/ruby/openssl/commit/fa1da69f92
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4275
-rw-r--r--ext/openssl/ossl_x509store.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/ext/openssl/ossl_x509store.c b/ext/openssl/ossl_x509store.c
index d29e6f5e42..596814887c 100644
--- a/ext/openssl/ossl_x509store.c
+++ b/ext/openssl/ossl_x509store.c
@@ -574,26 +574,13 @@ static VALUE
ossl_x509stctx_get_chain(VALUE self)
{
X509_STORE_CTX *ctx;
- STACK_OF(X509) *chain;
- X509 *x509;
- int i, num;
- VALUE ary;
+ const STACK_OF(X509) *chain;
GetX509StCtx(self, ctx);
- if((chain = X509_STORE_CTX_get0_chain(ctx)) == NULL){
- return Qnil;
- }
- if((num = sk_X509_num(chain)) < 0){
- OSSL_Debug("certs in chain < 0???");
- return rb_ary_new();
- }
- ary = rb_ary_new2(num);
- for(i = 0; i < num; i++) {
- x509 = sk_X509_value(chain, i);
- rb_ary_push(ary, ossl_x509_new(x509));
- }
-
- return ary;
+ chain = X509_STORE_CTX_get0_chain(ctx);
+ if (!chain)
+ return Qnil; /* Could be an empty array instead? */
+ return ossl_x509_sk2ary(chain);
}
/*