diff options
author | Michal Rokos <m.rokos@sh.cvut.cz> | 2001-11-21 21:31:56 +0000 |
---|---|---|
committer | Michal Rokos <m.rokos@sh.cvut.cz> | 2001-11-21 21:31:56 +0000 |
commit | 1c8834d13a4505af0c91530e1f505df325d45fe9 (patch) | |
tree | 5d385cf1931f04ee80bed016f1dbdcb209af5e02 /ossl_ns_spki.c | |
parent | 2577414c0428ea652b6ad18f66dd4e50bb89de3a (diff) | |
download | ruby-openssl-history-1c8834d13a4505af0c91530e1f505df325d45fe9.tar.gz |
- BN added (only proof of concept)
- indent changed
- rand.h to ossl.h added
Diffstat (limited to 'ossl_ns_spki.c')
-rw-r--r-- | ossl_ns_spki.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/ossl_ns_spki.c b/ossl_ns_spki.c index c11cf60..1f5a533 100644 --- a/ossl_ns_spki.c +++ b/ossl_ns_spki.c @@ -13,10 +13,7 @@ #define MakeSPKI(obj, spkip) {\ obj = Data_Make_Struct(cSPKI, ossl_spki, 0, ossl_spki_free, spkip);\ } - -#define GetSPKI(obj, spkip) {\ - Data_Get_Struct(obj, ossl_spki, spkip);\ -} +#define GetSPKI(obj, spkip) Data_Get_Struct(obj, ossl_spki, spkip) /* * Classes @@ -70,20 +67,20 @@ ossl_spki_initialize(int argc, VALUE *argv, VALUE self) rb_scan_args(argc, argv, "01", &buffer); - if (NIL_P(buffer)) { - if (!(spki = NETSCAPE_SPKI_new())) { - rb_raise(eSPKIError, "%s", ossl_error()); - } - } else switch (TYPE(buffer)) { + switch (TYPE(buffer)) { + case T_NIL: + spki = NETSCAPE_SPKI_new(); + break; case T_STRING: Check_SafeStr(buffer); - if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING(buffer)->ptr, -1))) { - rb_raise(eSPKIError, "%s", ossl_error()); - } + spki = NETSCAPE_SPKI_b64_decode(RSTRING(buffer)->ptr, -1); break; default: rb_raise(rb_eTypeError, "unsupported type"); } + if (!spki) { + rb_raise(eSPKIError, "%s", ossl_error()); + } spkip->spki = spki; return self; @@ -134,16 +131,14 @@ ossl_spki_get_public_key(VALUE self) { ossl_spki *spkip = NULL; EVP_PKEY *pkey = NULL; - VALUE pub_key; GetSPKI(self, spkip); if (!(pkey = NETSCAPE_SPKI_get_pubkey(spkip->spki))) { rb_raise(eSPKIError, "%s", ossl_error()); } - pub_key = ossl_pkey_new(pkey); - return pub_key; + return ossl_pkey_new(pkey); } static VALUE @@ -249,11 +244,11 @@ ossl_spki_verify(VALUE self, VALUE key) * NETSCAPE_SPKI init */ void -Init_ossl_spki(VALUE mNetscape) +Init_ossl_spki(VALUE module) { - eSPKIError = rb_define_class_under(mNetscape, "SPKIError", rb_eStandardError); + eSPKIError = rb_define_class_under(module, "SPKIError", rb_eStandardError); - cSPKI = rb_define_class_under(mNetscape, "SPKI", rb_cObject); + cSPKI = rb_define_class_under(module, "SPKI", rb_cObject); rb_define_singleton_method(cSPKI, "new", ossl_spki_s_new, -1); rb_define_method(cSPKI, "initialize", ossl_spki_initialize, -1); rb_define_method(cSPKI, "to_pem", ossl_spki_to_pem, 0); |