Skip to content

Commit

Permalink
* ext/openssl/ossl_ns_spki.c (ossl_spki_initialize): assume that
Browse files Browse the repository at this point in the history
  the argument is a DER string if Base64 decoding failed.

* ext/openssl/ossl_ns_pki.c (ossl_spki_to_der): new method.

* test/openssl/test_ns_spki.rb: add new file.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9113 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
gotoyuzo committed Sep 10, 2005
1 parent a4164e5 commit 5c1d0e3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
19 changes: 18 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
Sat Sep 10 10:05:51 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>

* ext/openssl/ossl_ns_spki.c (ossl_spki_initialize): assume that
the argument is a DER string if Base64 decoding failed.

* ext/openssl/ossl_ns_pki.c (ossl_spki_to_der): new method.

* test/openssl/test_ns_spki.rb: add new file.

Sat Sep 10 09:56:24 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>

* ext/openssl/lib/digest.rb: added SHA224, SHA256, SHA384 and SHA512.
these features are enabled if this library is compiled with
OpenSSL 0.9.8 or later.

* test/openssl/test_digest.rb: add test for new digests.

Sat Sep 10 09:51:30 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>

* ext/openssl/ossl.c (ossl_raise): should use ERR_peek_last_error
to get last error on the current thread. And should report
errors are on the stack while OpenSSL.debug is true.
errors on the stack while OpenSSL.debug is true.

* ext/openssl/ossl.c (ossl_get_errors): new method for debugging
this library.
Expand Down
30 changes: 28 additions & 2 deletions ext/openssl/ossl_ns_spki.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,44 @@ 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;

return 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)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5c1d0e3

Please sign in to comment.