Skip to content

Commit fa1da69

Browse files
committed
x509store: refactor X509::StoreContext#chain
Use ossl_x509_sk2ary() to create an array of OpenSSL::X509::Certificate from STACK_OF(X509).
1 parent d173700 commit fa1da69

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

ext/openssl/ossl_x509store.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -574,26 +574,13 @@ static VALUE
574574
ossl_x509stctx_get_chain(VALUE self)
575575
{
576576
X509_STORE_CTX *ctx;
577-
STACK_OF(X509) *chain;
578-
X509 *x509;
579-
int i, num;
580-
VALUE ary;
577+
const STACK_OF(X509) *chain;
581578

582579
GetX509StCtx(self, ctx);
583-
if((chain = X509_STORE_CTX_get0_chain(ctx)) == NULL){
584-
return Qnil;
585-
}
586-
if((num = sk_X509_num(chain)) < 0){
587-
OSSL_Debug("certs in chain < 0???");
588-
return rb_ary_new();
589-
}
590-
ary = rb_ary_new2(num);
591-
for(i = 0; i < num; i++) {
592-
x509 = sk_X509_value(chain, i);
593-
rb_ary_push(ary, ossl_x509_new(x509));
594-
}
595-
596-
return ary;
580+
chain = X509_STORE_CTX_get0_chain(ctx);
581+
if (!chain)
582+
return Qnil; /* Could be an empty array instead? */
583+
return ossl_x509_sk2ary(chain);
597584
}
598585

599586
/*

0 commit comments

Comments
 (0)