diff options
author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-22 20:47:55 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-22 20:47:55 +0000 |
commit | 8a94b1740ad5c1676c8b4574733961fc36b1ad78 (patch) | |
tree | f67e5ec733bf10339e89bba6b08293857b1a5a28 /ext/openssl/ossl_ns_spki.c | |
parent | f19fe6d957766910d8cd6567c36b29a40ecf9b46 (diff) | |
download | ruby-8a94b1740ad5c1676c8b4574733961fc36b1ad78.tar.gz |
* ext/openssl/ossl_ns_spki.c (ossl_spki_initialize): try to decode
the argument as a string.
* ext/openssl/ossl_ns_pki.c (ossl_spki_to_der): new method.
* ext/openssl/ossl_x509store.c (ossl_x509store_initialize): should
set @time to avoid warning.
* ext/openssl/ossl_x509store.c (ossl_x509store_set_default_paths,
X509_STORE_add_cert, X509_STORE_add_crl): should raise error if
wrapped functions fails.
* ext/openssl/ossl_ssl.c (ossl_sslctx_set_ciphers): fix error message.
* ext/openssl/ossl_x509req.c (ossl_x509req_set_attributes): get rid
of unused variable.
* test/openssl/test_ns_spki.rb: add new file.
* test/openssl/test_x509store.rb: add test for error.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9021 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_ns_spki.c')
-rw-r--r-- | ext/openssl/ossl_ns_spki.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/ext/openssl/ossl_ns_spki.c b/ext/openssl/ossl_ns_spki.c index c4ad05dea3..5cba529850 100644 --- a/ext/openssl/ossl_ns_spki.c +++ b/ext/openssl/ossl_ns_spki.c @@ -56,12 +56,17 @@ ossl_spki_initialize(int argc, VALUE *argv, VALUE self) { NETSCAPE_SPKI *spki; VALUE buffer; + unsigned char *p; if (rb_scan_args(argc, argv, "01", &buffer) == 0) { return self; } - if (!(spki = NETSCAPE_SPKI_b64_decode(StringValuePtr(buffer), -1))) { - ossl_raise(eSPKIError, NULL); + StringValue(buffer); + if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING(buffer)->ptr, -1))) { + p = RSTRING(buffer)->ptr; + if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING(buffer)->len))) { + ossl_raise(eSPKIError, NULL); + } } NETSCAPE_SPKI_free(DATA_PTR(self)); DATA_PTR(self) = spki; @@ -70,6 +75,26 @@ ossl_spki_initialize(int argc, VALUE *argv, VALUE self) } static VALUE +ossl_spki_to_der(VALUE self) +{ + NETSCAPE_SPKI *spki; + VALUE str; + long len; + unsigned char *p; + + GetSPKI(self, spki); + if ((len = i2d_NETSCAPE_SPKI(spki, NULL)) <= 0) + ossl_raise(eX509CertError, NULL); + str = rb_str_new(0, len); + p = RSTRING(str)->ptr; + if (i2d_NETSCAPE_SPKI(spki, &p) <= 0) + ossl_raise(eX509CertError, NULL); + ossl_str_adjust(str, p); + + return str; +} + +static VALUE ossl_spki_to_pem(VALUE self) { NETSCAPE_SPKI *spki; @@ -217,6 +242,7 @@ Init_ossl_ns_spki() rb_define_alloc_func(cSPKI, ossl_spki_alloc); rb_define_method(cSPKI, "initialize", ossl_spki_initialize, -1); + rb_define_method(cSPKI, "to_der", ossl_spki_to_der, 0); rb_define_method(cSPKI, "to_pem", ossl_spki_to_pem, 0); rb_define_alias(cSPKI, "to_s", "to_pem"); rb_define_method(cSPKI, "to_text", ossl_spki_print, 0); |