aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Rokos <m.rokos@sh.cvut.cz>2002-06-05 08:47:22 +0000
committerMichal Rokos <m.rokos@sh.cvut.cz>2002-06-05 08:47:22 +0000
commit9eb38c6de7024e3c9bae02fea182a2a3f0e306c9 (patch)
tree12f9edfa697c366b25fda980dceae9cd40aae6de
parent99402ac08472e831238d632c2e10b0e03700bc5b (diff)
downloadruby-openssl-history-9eb38c6de7024e3c9bae02fea182a2a3f0e306c9.tar.gz
HMAC and SPKI cleanups & ports
-rw-r--r--ChangeLog11
-rw-r--r--ossl.c38
-rw-r--r--ossl.h16
-rw-r--r--ossl_bn.c2
-rw-r--r--ossl_cipher.c2
-rw-r--r--ossl_digest.c69
-rw-r--r--ossl_hmac.c119
-rw-r--r--ossl_hmac.h20
-rw-r--r--ossl_ns_spki.c87
-rw-r--r--ossl_ns_spki.h21
-rw-r--r--ossl_pkey_dh.c2
11 files changed, 238 insertions, 149 deletions
diff --git a/ChangeLog b/ChangeLog
index e8cbb62..86c810a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,17 @@ ChangeLog for
### CHANGE LOG ###
+Wed, 5 Jun 2002 10:46:17 +0200 -- Michal Rokos <m.rokos@sh.cvut.cz>
+ * ns_spki.h: NEW (bits from ossl.h)
+ * ns_spki.c: cleanup & port to Ruby 1.8 interface
+
+Wed, 5 Jun 2002 10:14:54 +0200 -- Michal Rokos <m.rokos@sh.cvut.cz>
+ * hmac.h: NEW (bits from ossl.h)
+ * ossl.c: helper function 'string2hex'
+ * hmac.c: use 'string2hex'
+ * digest.c: ditto.
+ * hmac:c: cleanup
+
Tue, 4 Jun 2002 23:26:07 +0200 -- Michal Rokos <m.rokos@sh.cvut.cz>
* bn.c: cleanup (remove oddly initialized vars)
* config.c: ditto.
diff --git a/ossl.c b/ossl.c
index 624bff5..24b421e 100644
--- a/ossl.c
+++ b/ossl.c
@@ -90,6 +90,39 @@ time_to_time_t(VALUE time)
}
/*
+ * String to HEXString conversion
+ */
+int
+string2hex(char *buf, int buf_len, char **hexbuf, int *hexbuf_len)
+{
+ static const char hex[]="0123456789abcdef";
+ int i, len = 2 * buf_len;
+
+ if (buf_len < 0 || len < buf_len) { /* PARANOIA? */
+ return -1;
+ }
+ if (!hexbuf) {
+ if (hexbuf_len) {
+ *hexbuf_len = len;
+ }
+ return len;
+ }
+ if (!(*hexbuf = OPENSSL_malloc(len + 1))) {
+ return -1;
+ }
+ for (i = 0; i < buf_len; i++) {
+ (*hexbuf)[2 * i] = hex[((unsigned char)buf[i]) >> 4];
+ (*hexbuf)[2 * i + 1] = hex[buf[i] & 0x0f];
+ }
+ (*hexbuf)[2 * i] = '\0';
+
+ if (hexbuf_len) {
+ *hexbuf_len = len;
+ }
+ return len;
+}
+
+/*
* Modules
*/
VALUE mOSSL;
@@ -125,7 +158,6 @@ Init_openssl()
* Universe of Modules
*/
mOSSL = rb_define_module("OpenSSL");
- mNetscape = rb_define_module_under(mOSSL, "Netscape");
mPKCS7 = rb_define_module_under(mOSSL, "PKCS7");
mPKey = rb_define_module_under(mOSSL, "PKey");
mRandom = rb_define_module_under(mOSSL, "Random");
@@ -150,11 +182,11 @@ Init_openssl()
Init_ossl_cipher();
Init_ossl_config();
Init_ossl_digest();
- Init_ossl_hmac(mOSSL);
+ Init_ossl_hmac();
+ Init_ossl_ns_spki();
Init_ossl_pkcs7(mPKCS7);
Init_ossl_pkey(mPKey);
Init_ossl_rand(mRandom);
- Init_ossl_spki(mNetscape);
Init_ossl_ssl(mSSL);
Init_ossl_x509();
}
diff --git a/ossl.h b/ossl.h
index c8a48c2..0d2b27a 100644
--- a/ossl.h
+++ b/ossl.h
@@ -55,7 +55,6 @@ extern "C" {
* Common Module
*/
extern VALUE mOSSL;
-extern VALUE mNetscape;
extern VALUE mPKCS7;
extern VALUE mPKey;
extern VALUE mRandom;
@@ -69,8 +68,6 @@ VALUE eOSSLError;
/*
* Classes
*/
-extern VALUE cSPKI;
-extern VALUE eSPKIError;
extern VALUE eRandomError;
extern VALUE cSSLSocket;
extern VALUE eSSLError;
@@ -88,9 +85,6 @@ extern VALUE eDHError;
extern VALUE cPKCS7;
extern VALUE cPKCS7SignerInfo;
extern VALUE ePKCS7Error;
-/* HMAC */
-extern VALUE cHMAC;
-extern VALUE eHMACError;
/*
* CheckTypes
@@ -108,6 +102,11 @@ VALUE asn1time_to_time(ASN1_UTCTIME *);
time_t time_to_time_t(VALUE);
/*
+ * String to HEXString conversion
+ */
+int string2hex(char *, int, char **, int *);
+
+/*
* ERRor messages
*/
#define OSSL_ErrMsg() \
@@ -195,20 +194,19 @@ void Init_ossl_pkcs7(VALUE);
/*
* HMAC
*/
-void Init_ossl_hmac(VALUE);
#include "openssl_missing.h"
#include "ossl_bn.h"
#include "ossl_cipher.h"
#include "ossl_config.h"
#include "ossl_digest.h"
+#include "ossl_hmac.h"
+#include "ossl_ns_spki.h"
/*
* TODO
-#include "ossl_hmac.h"
#include "ossl_pkcs7.h"
#include "ossl_pkey.h"
#include "ossl_rand.h"
-#include "ossl_spki.h"
#include "ossl_ssl.h"
*/
#include "ossl_version.h"
diff --git a/ossl_bn.c b/ossl_bn.c
index 838a717..f22601f 100644
--- a/ossl_bn.c
+++ b/ossl_bn.c
@@ -24,7 +24,7 @@
} \
} while (0)
#define SafeGetBN(obj, bn) do { \
- OSSL_Check_Instance(obj, cBN); \
+ OSSL_Check_Kind(obj, cBN); \
GetBN(obj, bn); \
} while (0)
diff --git a/ossl_cipher.c b/ossl_cipher.c
index 9b27061..44e41a7 100644
--- a/ossl_cipher.c
+++ b/ossl_cipher.c
@@ -13,7 +13,7 @@
#define MakeCipher(obj, klass, ciphp) obj = Data_Make_Struct(klass, ossl_cipher, 0, ossl_cipher_free, ciphp)
#define GetCipher(obj, ciphp) Data_Get_Struct(obj, ossl_cipher, ciphp)
#define SafeGetCipher(obj, ciphp) do { \
- OSSL_Check_Instance(obj, cCipher); \
+ OSSL_Check_Kind(obj, cCipher); \
GetCipher(obj, ciphp); \
} while (0)
diff --git a/ossl_digest.c b/ossl_digest.c
index ef2cea7..7a444ba 100644
--- a/ossl_digest.c
+++ b/ossl_digest.c
@@ -23,7 +23,7 @@
} \
} while (0)
#define SafeGetDigest(obj, ctx) do { \
- OSSL_Check_Instance(obj, cDigest); \
+ OSSL_Check_Kind(obj, cDigest); \
GetDigest(obj, ctx); \
} while (0)
@@ -96,26 +96,34 @@ ossl_digest_update(VALUE self, VALUE data)
return self;
}
-static VALUE
-ossl_digest_digest(VALUE self)
+static void
+digest_final(EVP_MD_CTX *ctx, char **buf, int *buf_len)
{
- EVP_MD_CTX *ctx, final;
- char *digest_txt;
- int digest_len;
- VALUE digest;
-
- GetDigest(self, ctx);
-
+ EVP_MD_CTX final;
+
if (!EVP_MD_CTX_copy(&final, ctx)) {
OSSL_Raise(eDigestError, "");
}
- if (!(digest_txt = OPENSSL_malloc(EVP_MD_CTX_size(&final)))) {
+ if (!(*buf = OPENSSL_malloc(EVP_MD_CTX_size(&final)))) {
OSSL_Raise(eDigestError, "Cannot allocate mem for digest");
}
- EVP_DigestFinal(&final, digest_txt, &digest_len);
+ EVP_DigestFinal(&final, *buf, buf_len);
+}
- digest = rb_str_new(digest_txt, digest_len);
- OPENSSL_free(digest_txt);
+static VALUE
+ossl_digest_digest(VALUE self)
+{
+ EVP_MD_CTX *ctx;
+ char *buf;
+ int buf_len;
+ VALUE digest;
+
+ GetDigest(self, ctx);
+
+ digest_final(ctx, &buf, &buf_len);
+
+ digest = rb_str_new(buf, buf_len);
+ OPENSSL_free(buf);
return digest;
}
@@ -123,34 +131,22 @@ ossl_digest_digest(VALUE self)
static VALUE
ossl_digest_hexdigest(VALUE self)
{
- EVP_MD_CTX *ctx, final;
- static const char hex[]="0123456789abcdef";
- char *digest_txt = NULL, *hexdigest_txt = NULL;
- int i, digest_len;
+ EVP_MD_CTX *ctx;
+ char *buf, *hexbuf;
+ int buf_len;
VALUE hexdigest;
GetDigest(self, ctx);
- if (!EVP_MD_CTX_copy(&final, ctx)) {
- OSSL_Raise(eDigestError, "");
- }
- if (!(digest_txt = OPENSSL_malloc(EVP_MD_CTX_size(&final)))) {
- OSSL_Raise(eDigestError, "Cannot allocate memory for digest");
- }
- EVP_DigestFinal(&final, digest_txt, &digest_len);
-
- if (!(hexdigest_txt = OPENSSL_malloc(2 * digest_len + 1))) {
- OPENSSL_free(digest_txt);
+ digest_final(ctx, &buf, &buf_len);
+
+ if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * buf_len) {
+ OPENSSL_free(buf);
OSSL_Raise(eDigestError, "Memory alloc error");
}
- for (i = 0; i < digest_len; i++) {
- hexdigest_txt[2 * i] = hex[((unsigned char)digest_txt[i]) >> 4];
- hexdigest_txt[2 * i + 1] = hex[digest_txt[i] & 0x0f];
- }
- hexdigest_txt[2 * i] = '\0';
- hexdigest = rb_str_new(hexdigest_txt, 2 * digest_len);
- OPENSSL_free(digest_txt);
- OPENSSL_free(hexdigest_txt);
+ hexdigest = rb_str_new(hexbuf, 2 * buf_len);
+ OPENSSL_free(buf);
+ OPENSSL_free(hexbuf);
return hexdigest;
}
@@ -240,7 +236,6 @@ Init_ossl_digest()
rb_define_singleton_method(cDigest, "hexdigest", ossl_digest_s_hexdigest, 2);
rb_define_method(cDigest, "initialize", ossl_digest_initialize, 1);
- rb_enable_super(cDigest, "initialize");
rb_define_method(cDigest, "clone", ossl_digest_clone, 0);
diff --git a/ossl_hmac.c b/ossl_hmac.c
index 2c37a95..a96aafa 100644
--- a/ossl_hmac.c
+++ b/ossl_hmac.c
@@ -12,8 +12,18 @@
#include "ossl.h"
-#define WrapHMAC(obj, ctx) obj = Data_Wrap_Struct(cHMAC, 0, CRYPTO_free, ctx)
-#define GetHMAC(obj, ctx) Data_Get_Struct(obj, HMAC_CTX, ctx)
+#define WrapHMAC(obj, ctx) do { \
+ if (!ctx) { \
+ rb_raise(rb_eRuntimeError, "HMAC wasn't initialized"); \
+ } \
+ obj = Data_Wrap_Struct(cHMAC, 0, CRYPTO_free, ctx); \
+} while (0)
+#define GetHMAC(obj, ctx) do { \
+ Data_Get_Struct(obj, HMAC_CTX, ctx); \
+ if (!ctx) { \
+ rb_raise(rb_eRuntimeError, "HMAC wasn't initialized"); \
+ } \
+} while (0)
/*
* Classes
@@ -29,9 +39,9 @@ VALUE eHMACError;
* Private
*/
static VALUE
-ossl_hmac_s_new(int argc, VALUE *argv, VALUE klass)
+ossl_hmac_s_allocate(VALUE klass)
{
- HMAC_CTX *ctx = NULL;
+ HMAC_CTX *ctx;
VALUE obj;
if (!(ctx = OPENSSL_malloc(sizeof(HMAC_CTX)))) {
@@ -39,22 +49,17 @@ ossl_hmac_s_new(int argc, VALUE *argv, VALUE klass)
}
WrapHMAC(obj, ctx);
- rb_obj_call_init(obj, argc, argv);
-
return obj;
}
static VALUE
-ossl_hmac_initialize(int argc, VALUE *argv, VALUE self)
+ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
{
- HMAC_CTX *ctx = NULL;
- VALUE key, digest;
+ HMAC_CTX *ctx;
GetHMAC(self, ctx);
- rb_scan_args(argc, argv, "20", &key, &digest);
-
- key = rb_String(key);
+ StringValue(key);
HMAC_Init(ctx, RSTRING(key)->ptr, RSTRING(key)->len, ossl_digest_get_EVP_MD(digest));
@@ -64,95 +69,91 @@ ossl_hmac_initialize(int argc, VALUE *argv, VALUE self)
static VALUE
ossl_hmac_update(VALUE self, VALUE data)
{
- HMAC_CTX *ctx = NULL;
+ HMAC_CTX *ctx;
GetHMAC(self, ctx);
- data = rb_String(data);
+ StringValue(data);
HMAC_Update(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
return self;
}
-static VALUE
-ossl_hmac_hmac(VALUE self)
+static void
+hmac_final(HMAC_CTX *ctx, char **buf, int *buf_len)
{
- HMAC_CTX *ctx = NULL, final;
- char *buf = NULL;
- int buf_len = 0;
- VALUE str;
-
- GetHMAC(self, ctx);
-
+ HMAC_CTX final;
+
if (!HMAC_CTX_copy(&final, ctx)) {
OSSL_Raise(eHMACError, "");
}
- if (!(buf = OPENSSL_malloc(HMAC_size(&final)))) {
+ if (!(*buf = OPENSSL_malloc(HMAC_size(&final)))) {
OSSL_Raise(eHMACError, "Cannot allocate memory for hmac");
}
- HMAC_Final(&final, buf, &buf_len);
+ HMAC_Final(&final, *buf, buf_len);
+}
- str = rb_str_new(buf, buf_len);
+static VALUE
+ossl_hmac_digest(VALUE self)
+{
+ HMAC_CTX *ctx;
+ char *buf;
+ int buf_len;
+ VALUE digest;
+
+ GetHMAC(self, ctx);
+
+ hmac_final(ctx, &buf, &buf_len);
+
+ digest = rb_str_new(buf, buf_len);
OPENSSL_free(buf);
- return str;
+ return digest;
}
static VALUE
-ossl_hmac_hexhmac(VALUE self)
+ossl_hmac_hexdigest(VALUE self)
{
- HMAC_CTX *ctx = NULL, final;
- static const char hex[]="0123456789abcdef";
- char *buf = NULL, *hexbuf = NULL;
- int i,buf_len = 0;
- VALUE str;
+ HMAC_CTX *ctx;
+ char *buf, *hexbuf;
+ int buf_len;
+ VALUE hexdigest;
GetHMAC(self, ctx);
- if (!HMAC_CTX_copy(&final, ctx)) {
- OSSL_Raise(eHMACError, "Cannot copy HMAC CTX");
- }
- if (!(buf = OPENSSL_malloc(HMAC_size(&final)))) {
- OSSL_Raise(eHMACError, "Cannot allocate memory for hmac");
- }
- HMAC_Final(&final, buf, &buf_len);
+ hmac_final(ctx, &buf, &buf_len);
- if (!(hexbuf = OPENSSL_malloc(2*buf_len+1))) {
+ if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * buf_len) {
OPENSSL_free(buf);
OSSL_Raise(eHMACError, "Memory alloc error");
}
- for (i = 0; i < buf_len; i++) {
- hexbuf[i + i] = hex[((unsigned char)buf[i]) >> 4];
- hexbuf[i + i + 1] = hex[buf[i] & 0x0f];
- }
- hexbuf[i + i] = '\0';
-
- str = rb_str_new(hexbuf, 2*buf_len);
-
+ hexdigest = rb_str_new(hexbuf, 2 * buf_len);
OPENSSL_free(buf);
OPENSSL_free(hexbuf);
- return str;
+ return hexdigest;
}
/*
* INIT
*/
void
-Init_ossl_hmac(VALUE module)
+Init_ossl_hmac()
{
- eHMACError = rb_define_class_under(module, "HMACError", eOSSLError);
+ eHMACError = rb_define_class_under(mOSSL, "HMACError", eOSSLError);
+
+ cHMAC = rb_define_class_under(mOSSL, "HMAC", rb_cObject);
+
+ rb_define_singleton_method(cHMAC, "allocate", ossl_hmac_s_allocate, 0);
+ rb_define_method(cHMAC, "initialize", ossl_hmac_initialize, 2);
- cHMAC = rb_define_class_under(module, "HMAC", rb_cObject);
- rb_define_singleton_method(cHMAC, "new", ossl_hmac_s_new, -1);
- rb_define_method(cHMAC, "initialize", ossl_hmac_initialize, -1);
rb_define_method(cHMAC, "update", ossl_hmac_update, 1);
rb_define_alias(cHMAC, "<<", "update");
- rb_define_method(cHMAC, "hmac", ossl_hmac_hmac, 0);
- rb_define_method(cHMAC, "hexhmac", ossl_hmac_hexhmac, 0);
- rb_define_alias(cHMAC, "inspect", "hexhmac");
- rb_define_alias(cHMAC, "to_s", "hexhmac");
+ rb_define_method(cHMAC, "digest", ossl_hmac_digest, 0);
+ rb_define_method(cHMAC, "hexdigest", ossl_hmac_hexdigest, 0);
+ rb_define_alias(cHMAC, "inspect", "hexdigest");
+ rb_define_alias(cHMAC, "to_s", "hexdigest");
}
#else /* NO_HMAC */
diff --git a/ossl_hmac.h b/ossl_hmac.h
new file mode 100644
index 0000000..ca6600d
--- /dev/null
+++ b/ossl_hmac.h
@@ -0,0 +1,20 @@
+/*
+ * $Id$
+ * 'OpenSSL for Ruby' project
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
+ * All rights reserved.
+ */
+/*
+ * This program is licenced under the same licence as Ruby.
+ * (See the file 'LICENCE'.)
+ */
+#if !defined(_OSSL_HMAC_H_)
+#define _OSSL_HMAC_H_
+
+extern VALUE cHMAC;
+extern VALUE eHMACError;
+
+void Init_ossl_hmac();
+
+#endif /* _OSSL_HMAC_H_ */
+
diff --git a/ossl_ns_spki.c b/ossl_ns_spki.c
index f1c0f89..d23cd97 100644
--- a/ossl_ns_spki.c
+++ b/ossl_ns_spki.c
@@ -10,8 +10,18 @@
*/
#include "ossl.h"
-#define WrapSPKI(obj, spki) obj = Data_Wrap_Struct(cSPKI, 0, NETSCAPE_SPKI_free, spki)
-#define GetSPKI(obj, spki) Data_Get_Struct(obj, NETSCAPE_SPKI, spki)
+#define WrapSPKI(obj, spki) do { \
+ if (!spki) { \
+ rb_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
+ } \
+ obj = Data_Wrap_Struct(cSPKI, 0, NETSCAPE_SPKI_free, spki); \
+} while (0)
+#define GetSPKI(obj, spki) do { \
+ Data_Get_Struct(obj, NETSCAPE_SPKI, spki); \
+ if (!spki) { \
+ rb_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
+ } \
+} while (0)
/*
* Classes
@@ -27,9 +37,9 @@ VALUE eSPKIError;
* Private functions
*/
static VALUE
-ossl_spki_s_new(int argc, VALUE *argv, VALUE klass)
+ossl_spki_s_allocate(VALUE klass)
{
- NETSCAPE_SPKI *spki = NULL;
+ NETSCAPE_SPKI *spki;
VALUE obj;
if (!(spki = NETSCAPE_SPKI_new())) {
@@ -38,23 +48,20 @@ ossl_spki_s_new(int argc, VALUE *argv, VALUE klass)
WrapSPKI(obj, spki);
- rb_obj_call_init(obj, argc, argv);
-
return obj;
}
static VALUE
ossl_spki_initialize(int argc, VALUE *argv, VALUE self)
{
- NETSCAPE_SPKI *spki = NULL;
+ NETSCAPE_SPKI *spki;
VALUE buffer;
- if (argc == 0)
+ if (rb_scan_args(argc, argv, "01", &buffer) == 0) {
return self;
+ }
- buffer = rb_String(argv[0]);
-
- if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING(buffer)->ptr, -1))) {
+ if (!(spki = NETSCAPE_SPKI_b64_decode(StringValuePtr(buffer), -1))) {
OSSL_Raise(eSPKIError, "");
}
@@ -67,8 +74,8 @@ ossl_spki_initialize(int argc, VALUE *argv, VALUE self)
static VALUE
ossl_spki_to_pem(VALUE self)
{
- NETSCAPE_SPKI *spki = NULL;
- char *data = NULL;
+ NETSCAPE_SPKI *spki;
+ char *data;
VALUE str;
GetSPKI(self, spki);
@@ -84,11 +91,11 @@ ossl_spki_to_pem(VALUE self)
}
static VALUE
-ossl_spki_to_text(VALUE self)
+ossl_spki_print(VALUE self)
{
- NETSCAPE_SPKI *spki = NULL;
- BIO *out = NULL;
- BUF_MEM *buf = NULL;
+ NETSCAPE_SPKI *spki;
+ BIO *out;
+ BUF_MEM *buf;
VALUE str;
GetSPKI(self, spki);
@@ -110,8 +117,8 @@ ossl_spki_to_text(VALUE self)
static VALUE
ossl_spki_get_public_key(VALUE self)
{
- NETSCAPE_SPKI *spki = NULL;
- EVP_PKEY *pkey = NULL;
+ NETSCAPE_SPKI *spki;
+ EVP_PKEY *pkey;
GetSPKI(self, spki);
@@ -125,8 +132,8 @@ ossl_spki_get_public_key(VALUE self)
static VALUE
ossl_spki_set_public_key(VALUE self, VALUE pubk)
{
- NETSCAPE_SPKI *spki = NULL;
- EVP_PKEY *pkey = NULL;
+ NETSCAPE_SPKI *spki;
+ EVP_PKEY *pkey;
GetSPKI(self, spki);
@@ -143,7 +150,7 @@ ossl_spki_set_public_key(VALUE self, VALUE pubk)
static VALUE
ossl_spki_get_challenge(VALUE self)
{
- NETSCAPE_SPKI *spki = NULL;
+ NETSCAPE_SPKI *spki;
GetSPKI(self, spki);
@@ -156,11 +163,11 @@ ossl_spki_get_challenge(VALUE self)
static VALUE
ossl_spki_set_challenge(VALUE self, VALUE str)
{
- NETSCAPE_SPKI *spki = NULL;
+ NETSCAPE_SPKI *spki;
GetSPKI(self, spki);
-
- str = rb_String(str);
+
+ StringValue(str);
if (!ASN1_STRING_set(spki->spkac->challenge, RSTRING(str)->ptr, RSTRING(str)->len)) {
OSSL_Raise(eSPKIError, "");
@@ -172,9 +179,9 @@ ossl_spki_set_challenge(VALUE self, VALUE str)
static VALUE
ossl_spki_sign(VALUE self, VALUE key, VALUE digest)
{
- NETSCAPE_SPKI *spki = NULL;
- EVP_PKEY *pkey = NULL;
- const EVP_MD *md = NULL;
+ NETSCAPE_SPKI *spki;
+ EVP_PKEY *pkey;
+ const EVP_MD *md;
GetSPKI(self, spki);
@@ -199,9 +206,9 @@ ossl_spki_sign(VALUE self, VALUE key, VALUE digest)
static VALUE
ossl_spki_verify(VALUE self, VALUE key)
{
- NETSCAPE_SPKI *spki = NULL;
- EVP_PKEY *pkey = NULL;
- int result = 0;
+ NETSCAPE_SPKI *spki;
+ EVP_PKEY *pkey;
+ int result;
GetSPKI(self, spki);
@@ -212,9 +219,9 @@ ossl_spki_verify(VALUE self, VALUE key)
if (result < 0) {
OSSL_Raise(eSPKIError, "");
- } else if (result > 0)
+ } else if (result > 0) {
return Qtrue;
-
+ }
return Qfalse;
}
@@ -222,16 +229,20 @@ ossl_spki_verify(VALUE self, VALUE key)
* NETSCAPE_SPKI init
*/
void
-Init_ossl_spki(VALUE module)
+Init_ossl_ns_spki()
{
- eSPKIError = rb_define_class_under(module, "SPKIError", eOSSLError);
+ mNetscape = rb_define_module_under(mOSSL, "Netscape");
+
+ eSPKIError = rb_define_class_under(mNetscape, "SPKIError", eOSSLError);
- cSPKI = rb_define_class_under(module, "SPKI", rb_cObject);
- rb_define_singleton_method(cSPKI, "new", ossl_spki_s_new, -1);
+ cSPKI = rb_define_class_under(mNetscape, "SPKI", rb_cObject);
+
+ rb_define_singleton_method(cSPKI, "allocate", ossl_spki_s_allocate, 0);
rb_define_method(cSPKI, "initialize", ossl_spki_initialize, -1);
+
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_to_text, 0);
+ rb_define_method(cSPKI, "to_text", ossl_spki_print, 0);
rb_define_method(cSPKI, "public_key", ossl_spki_get_public_key, 0);
rb_define_method(cSPKI, "public_key=", ossl_spki_set_public_key, 1);
rb_define_method(cSPKI, "sign", ossl_spki_sign, 2);
diff --git a/ossl_ns_spki.h b/ossl_ns_spki.h
new file mode 100644
index 0000000..9977035
--- /dev/null
+++ b/ossl_ns_spki.h
@@ -0,0 +1,21 @@
+/*
+ * $Id$
+ * 'OpenSSL for Ruby' project
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
+ * All rights reserved.
+ */
+/*
+ * This program is licenced under the same licence as Ruby.
+ * (See the file 'LICENCE'.)
+ */
+#if !defined(_OSSL_NS_SPKI_H_)
+#define _OSSL_NS_SPKI_H_
+
+extern VALUE mNetscape;
+extern VALUE cSPKI;
+extern VALUE eSPKIError;
+
+void Init_ossl_ns_spki(void);
+
+#endif /* _OSSL_NS_SPKI_H_ */
+
diff --git a/ossl_pkey_dh.c b/ossl_pkey_dh.c
index afe2f16..9b79b9c 100644
--- a/ossl_pkey_dh.c
+++ b/ossl_pkey_dh.c
@@ -78,7 +78,7 @@ ossl_dh_get_DH(VALUE obj)
ossl_dh *dhp = NULL;
DH *dh = NULL;
- OSSL_Check_Instance(obj, cDH);
+ OSSL_Check_Kind(obj, cDH);
GetDH(obj, dhp);
dh = DHparams_dup(dhp->dh);