1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/openssl/ossl.c (ossl_x509_sk2ary, ossl_x509crl_sk2ary): add

functions to convert STACK into Array.

* ext/openssl/ossl.h: add prototypes.

* ext/openssl/ossl_pkcs7.c (ossl_pkcs7_set_certificates,
  ossl_pkcs7_get_certificates, ossl_pkcs7_get_crls,
  ossl_pkcs7_set_crls): add functions for PKCS7#certificates=
  PKCS7#certificates, PKCS7#crls= and PKCS7#crls.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
gotoyuzo 2003-11-11 21:20:20 +00:00
parent 2fc95b6399
commit ed2a386f58
4 changed files with 99 additions and 7 deletions

View file

@ -1,3 +1,15 @@
Wed Nov 12 06:11:39 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl.c (ossl_x509_sk2ary, ossl_x509crl_sk2ary):
add functions to convert STACK into Array.
* ext/openssl/ossl.h: add prototypes.
* ext/openssl/ossl_pkcs7.c (ossl_pkcs7_set_certificates,
ossl_pkcs7_get_certificates, ossl_pkcs7_get_crls,
ossl_pkcs7_set_crls): add functions for PKCS7#certificates=
PKCS7#certificates, PKCS7#crls= and PKCS7#crls.
Tue Nov 12 00:47:00 2003 Nathaniel Talbott <ntalbott@ruby-lang.org>
* lib/test/unit/ui/testrunnermediator.rb: should require 'test/unit'.
@ -17,7 +29,7 @@ Tue Nov 11 10:42:41 2003 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: raise an exception when creating TkWindow
object, because TkWindow class is an abstract class.
Tue Nov 11 03:30:43 JST 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
Tue Nov 11 03:30:43 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/ext/openssl/ossl_conf.c (ossl_config_get_value): return nil
if the specified value doesn't exist.

View file

@ -90,8 +90,7 @@ ossl_x509_ary2sk(VALUE ary)
return sk;
}
#if 0
#define OSSL_SK2ARY(name, type) \
#define OSSL_IMPL_SK2ARY(name, type) \
VALUE \
ossl_##name##_sk2ary(STACK *sk) \
{ \
@ -101,7 +100,7 @@ ossl_##name##_sk2ary(STACK *sk) \
\
if (!sk) { \
OSSL_Debug("empty sk!"); \
return rb_ary_new(); \
return Qnil; \
} \
num = sk_num(sk); \
if (num < 0) { \
@ -116,9 +115,8 @@ ossl_##name##_sk2ary(STACK *sk) \
} \
return ary; \
}
OSSL_SK2ARY(x509, X509)
OSSL_SK2ARY(x509crl, X509_CRL)
#endif
OSSL_IMPL_SK2ARY(x509, X509)
OSSL_IMPL_SK2ARY(x509crl, X509_CRL)
static VALUE
ossl_str_new(int size)

View file

@ -108,6 +108,8 @@ int string2hex(char *, int, char **, int *);
STACK_OF(X509) *ossl_x509_ary2sk0(VALUE);
STACK_OF(X509) *ossl_x509_ary2sk(VALUE);
STACK_OF(X509) *ossl_protect_x509_ary2sk(VALUE,int*);
VALUE ossl_x509_sk2ary(STACK_OF(X509) *certs);
VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl);
VALUE ossl_buf2str(char *buf, int len);
#define ossl_str_adjust(str, p) \
do{\

View file

@ -479,6 +479,57 @@ ossl_pkcs7_add_certificate(VALUE self, VALUE cert)
return self;
}
static STACK *
pkcs7_get_certs_or_crls(VALUE self, int want_certs)
{
PKCS7 *pkcs7;
STACK_OF(X509) *certs;
STACK_OF(X509_CRL) *crls;
int i;
GetPKCS7(self, pkcs7);
i = OBJ_obj2nid(pkcs7->type);
switch(i){
case NID_pkcs7_signed:
certs = pkcs7->d.sign->cert;
crls = pkcs7->d.sign->crl;
break;
case NID_pkcs7_signedAndEnveloped:
certs = pkcs7->d.signed_and_enveloped->cert;
crls = pkcs7->d.signed_and_enveloped->crl;
break;
default:
certs = crls = NULL;
}
return want_certs ? certs : crls;
}
static VALUE
ossl_pkcs7_set_certs_i(VALUE i, VALUE arg)
{
return ossl_pkcs7_add_certificate(arg, i);
}
static VALUE
ossl_pkcs7_set_certificates(VALUE self, VALUE ary)
{
STACK_OF(X509) *certs;
X509 *cert;
certs = pkcs7_get_certs_or_crls(self, 1);
while((cert = sk_X509_pop(certs))) X509_free(cert);
rb_iterate(rb_each, ary, ossl_pkcs7_set_certs_i, self);
return ary;
}
static VALUE
ossl_pkcs7_get_certificates(VALUE self)
{
return ossl_x509_sk2ary(pkcs7_get_certs_or_crls(self, 1));
}
static VALUE
ossl_pkcs7_add_crl(VALUE self, VALUE crl)
{
@ -494,6 +545,31 @@ ossl_pkcs7_add_crl(VALUE self, VALUE crl)
return self;
}
static VALUE
ossl_pkcs7_set_crls_i(VALUE i, VALUE arg)
{
return ossl_pkcs7_add_crl(arg, i);
}
static VALUE
ossl_pkcs7_set_crls(VALUE self, VALUE ary)
{
STACK_OF(X509_CRL) *crls;
X509_CRL *crl;
crls = pkcs7_get_certs_or_crls(self, 0);
while((crl = sk_X509_CRL_pop(crls))) X509_CRL_free(crl);
rb_iterate(rb_each, ary, ossl_pkcs7_set_crls_i, self);
return ary;
}
static VALUE
ossl_pkcs7_get_crls(VALUE self)
{
return ossl_x509crl_sk2ary(pkcs7_get_certs_or_crls(self, 0));
}
static VALUE
ossl_pkcs7_verify(int argc, VALUE *argv, VALUE self)
{
@ -747,7 +823,11 @@ Init_ossl_pkcs7()
rb_define_method(cPKCS7, "signers", ossl_pkcs7_get_signer, 0);
rb_define_method(cPKCS7, "add_recipient", ossl_pkcs7_add_recipient, 1);
rb_define_method(cPKCS7, "add_certificate", ossl_pkcs7_add_certificate, 1);
rb_define_method(cPKCS7, "certificates=", ossl_pkcs7_set_certificates, 1);
rb_define_method(cPKCS7, "certificates", ossl_pkcs7_get_certificates, 0);
rb_define_method(cPKCS7, "add_crl", ossl_pkcs7_add_crl, 1);
rb_define_method(cPKCS7, "crls=", ossl_pkcs7_set_crls, 1);
rb_define_method(cPKCS7, "crls", ossl_pkcs7_get_crls, 0);
rb_define_method(cPKCS7, "add_data", ossl_pkcs7_add_data, 1);
rb_define_alias(cPKCS7, "data=", "add_data");
rb_define_method(cPKCS7, "verify", ossl_pkcs7_verify, -1);