ext/rubysl/openssl/ossl_x509cert.c in rubysl-openssl-2.2.1 vs ext/rubysl/openssl/ossl_x509cert.c in rubysl-openssl-2.3.0
- old
+ new
@@ -1,7 +1,7 @@
/*
- * $Id$
+ * $Id: ossl_x509cert.c 48810 2014-12-12 23:38:55Z nobu $
* 'OpenSSL for Ruby' project
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
* All rights reserved.
*/
/*
@@ -12,14 +12,14 @@
#define WrapX509(klass, obj, x509) do { \
if (!(x509)) { \
ossl_raise(rb_eRuntimeError, "CERT wasn't initialized!"); \
} \
- (obj) = Data_Wrap_Struct((klass), 0, X509_free, (x509)); \
+ (obj) = TypedData_Wrap_Struct((klass), &ossl_x509_type, (x509)); \
} while (0)
#define GetX509(obj, x509) do { \
- Data_Get_Struct((obj), X509, (x509)); \
+ TypedData_Get_Struct((obj), X509, &ossl_x509_type, (x509)); \
if (!(x509)) { \
ossl_raise(rb_eRuntimeError, "CERT wasn't initialized!"); \
} \
} while (0)
#define SafeGetX509(obj, x509) do { \
@@ -31,10 +31,24 @@
* Classes
*/
VALUE cX509Cert;
VALUE eX509CertError;
+static void
+ossl_x509_free(void *ptr)
+{
+ X509_free(ptr);
+}
+
+static const rb_data_type_t ossl_x509_type = {
+ "OpenSSL/X509",
+ {
+ 0, ossl_x509_free,
+ },
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
/*
* Public
*/
VALUE
ossl_x509_new(X509 *x509)
@@ -691,45 +705,25 @@
}
static VALUE
ossl_x509_inspect(VALUE self)
{
- VALUE str;
- const char *cname = rb_class2name(rb_obj_class(self));
-
- str = rb_str_new2("#<");
- rb_str_cat2(str, cname);
- rb_str_cat2(str, " ");
-
- rb_str_cat2(str, "subject=");
- rb_str_append(str, rb_inspect(ossl_x509_get_subject(self)));
- rb_str_cat2(str, ", ");
-
- rb_str_cat2(str, "issuer=");
- rb_str_append(str, rb_inspect(ossl_x509_get_issuer(self)));
- rb_str_cat2(str, ", ");
-
- rb_str_cat2(str, "serial=");
- rb_str_append(str, rb_inspect(ossl_x509_get_serial(self)));
- rb_str_cat2(str, ", ");
-
- rb_str_cat2(str, "not_before=");
- rb_str_append(str, rb_inspect(ossl_x509_get_not_before(self)));
- rb_str_cat2(str, ", ");
-
- rb_str_cat2(str, "not_after=");
- rb_str_append(str, rb_inspect(ossl_x509_get_not_after(self)));
-
- str = rb_str_cat2(str, ">");
-
- return str;
+ return rb_sprintf("#<%"PRIsVALUE": subject=%+"PRIsVALUE", "
+ "issuer=%+"PRIsVALUE", serial=%+"PRIsVALUE", "
+ "not_before=%+"PRIsVALUE", not_after=%+"PRIsVALUE">",
+ rb_obj_class(self),
+ ossl_x509_get_subject(self),
+ ossl_x509_get_issuer(self),
+ ossl_x509_get_serial(self),
+ ossl_x509_get_not_before(self),
+ ossl_x509_get_not_after(self));
}
/*
* INIT
*/
void
-Init_ossl_x509cert()
+Init_ossl_x509cert(void)
{
#if 0
mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
mX509 = rb_define_module_under(mOSSL, "X509");