aboutsummaryrefslogtreecommitdiffstats
path: root/ossl_x509attr.c
diff options
context:
space:
mode:
authorMichal Rokos <m.rokos@sh.cvut.cz>2002-01-04 11:12:22 +0000
committerMichal Rokos <m.rokos@sh.cvut.cz>2002-01-04 11:12:22 +0000
commit30c7790a512172b5254775fbad8f601d5638c1e6 (patch)
tree39a0ceb2db8fcd07e8b82bc107e5cc2a05df9d24 /ossl_x509attr.c
parent99d5a24aa57c9eb4ac792a36e0947dc5df84fe8c (diff)
downloadruby-openssl-history-30c7790a512172b5254775fbad8f601d5638c1e6.tar.gz
* Further checking (Check_SafeStr, memory leaks)
Diffstat (limited to 'ossl_x509attr.c')
-rw-r--r--ossl_x509attr.c110
1 files changed, 50 insertions, 60 deletions
diff --git a/ossl_x509attr.c b/ossl_x509attr.c
index a80b4ad..ba98045 100644
--- a/ossl_x509attr.c
+++ b/ossl_x509attr.c
@@ -13,9 +13,9 @@
#define MakeX509Attr(obj, attrp) {\
obj = Data_Make_Struct(cX509Attribute, ossl_x509attr, 0, ossl_x509attr_free, attrp);\
}
-#define GetX509Attr_unsafe(obj, attrp) Data_Get_Struct(obj, ossl_x509attr, attrp);
+
#define GetX509Attr(obj, attrp) {\
- GetX509Attr_unsafe(obj, attrp);\
+ Data_Get_Struct(obj, ossl_x509attr, attrp);\
if (!attrp->attribute) rb_raise(eX509AttributeError, "not initialized!");\
}
@@ -55,7 +55,7 @@ ossl_x509attr_new_null(void)
MakeX509Attr(obj, attrp);
if (!(attrp->attribute = X509_ATTRIBUTE_new()))
- rb_raise(eX509AttributeError, "%s", ossl_error());
+ OSSL_Raise(eX509AttributeError, "");
return obj;
}
@@ -71,9 +71,8 @@ ossl_x509attr_new(X509_ATTRIBUTE *attr)
MakeX509Attr(obj, attrp);
- if (!(attrp->attribute = X509_ATTRIBUTE_dup(attr))) {
- rb_raise(eX509AttributeError, "%s", ossl_error());
- }
+ if (!(attrp->attribute = X509_ATTRIBUTE_dup(attr)))
+ OSSL_Raise(eX509AttributeError, "");
return obj;
}
@@ -84,12 +83,11 @@ ossl_x509attr_get_X509_ATTRIBUTE(VALUE obj)
ossl_x509attr *attrp = NULL;
X509_ATTRIBUTE *attr = NULL;
- OSSL_Check_Type(obj, cX509Attribute);
-
+ OSSL_Check_Type(obj, cX509Attribute);
GetX509Attr(obj, attrp);
if (!(attr = X509_ATTRIBUTE_dup(attrp->attribute)))
- rb_raise(eX509AttributeError, "%s", ossl_error());
+ OSSL_Raise(eX509AttributeError, "");
return attr;
}
@@ -98,24 +96,12 @@ ossl_x509attr_get_X509_ATTRIBUTE(VALUE obj)
* private
*/
static VALUE
-ossl_x509attr_s_new(int argc, VALUE *argv, VALUE klass)
+ossl_x509attr_s_new_from_array(VALUE klass, VALUE ary)
{
ossl_x509attr *attrp = NULL;
- VALUE obj;
-
- MakeX509Attr(obj, attrp);
-
- rb_obj_call_init(obj, argc, argv);
-
- return obj;
-}
-
-X509_ATTRIBUTE *
-ary_to_x509attr(VALUE ary)
-{
X509_ATTRIBUTE *attr = NULL;
int nid = NID_undef;
- VALUE item;
+ VALUE item, obj;
Check_Type(ary, T_ARRAY);
@@ -125,55 +111,61 @@ ary_to_x509attr(VALUE ary)
/* key [0] */
item = RARRAY(ary)->ptr[0];
- Check_Type(item, T_STRING);
+ Check_SafeStr(item);
if (!(nid = OBJ_ln2nid(RSTRING(item)->ptr)))
if (!(nid = OBJ_sn2nid(RSTRING(item)->ptr)))
- rb_raise(eX509AttributeError, "%s", ossl_error());
+ OSSL_Raise(eX509AttributeError, "");
/* data [1] */
item = RARRAY(ary)->ptr[1];
- Check_Type(item, T_STRING);
+ Check_SafeStr(item);
- if (!(attr = X509_ATTRIBUTE_create(nid, MBSTRING_ASC, RSTRING(item)->ptr))) {
- rb_raise(eX509AttributeError, "%s", ossl_error());
- }
+ if (!(attr = X509_ATTRIBUTE_create(nid, MBSTRING_ASC, RSTRING(item)->ptr)))
+ OSSL_Raise(eX509AttributeError, "");
- return attr;
+ MakeX509Attr(obj, attrp);
+ attrp->attribute = attr;
+
+ return obj;
}
-static VALUE
-ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
+/*
+ * is there any print for attribute?
+ * (NO, but check t_req.c in crypto/asn1)
+ *
+static VALUE
+ossl_x509attr_to_a(VALUE self)
{
ossl_x509attr *attrp = NULL;
- X509_ATTRIBUTE *attr = NULL;
- VALUE arg1, arg2, ary;
-
- GetX509Attr_unsafe(self, attrp);
+ BIO *out = NULL;
+ BUF_MEM *buf = NULL;
+ int nid = NID_undef;
+ VALUE ary, value;
- switch (rb_scan_args(argc, argv, "02", &arg1, &arg2)) {
- case 0:
- attr = X509_ATTRIBUTE_new();
- break;
- case 1:
- Check_Type(arg1, T_ARRAY);
- attr = ary_to_x509attr(ary);
- break;
- case 2:
- ary = rb_ary_new2(2);
- rb_ary_push(ary, arg1);
- rb_ary_push(ary, arg2);
- attr = ary_to_x509attr(ary);
- break;
- default:
- rb_raise(rb_eTypeError, "unsupported type");
- }
- if (!attr)
- rb_raise(eX509AttributeError, "%s", ossl_error());
+ GetX509Attr(obj, attrp);
- attrp->attribute = attr;
+ ary = rb_ary_new2(2);
+
+ nid = OBJ_obj2nid(X509_ATTRIBUTE_get0_object(attrp->attribute));
+ rb_ary_push(ary, rb_str_new2(OBJ_nid2sn(nid)));
- return self;
+ if (!(out = BIO_new(BIO_s_mem())))
+ OSSL_Raise(eX509ExtensionError, "");
+
+ if (!X509V3_???_print(out, extp->extension, 0, 0)) {
+ BIO_free(out);
+ OSSL_Raise(eX509ExtensionError, "");
+ }
+ BIO_get_mem_ptr(out, &buf);
+ value = rb_str_new(buf->data, buf->length);
+ BIO_free(out);
+
+ rb_funcall(value, rb_intern("tr!"), 2, rb_str_new2("\n"), rb_str_new2(","));
+ rb_ary_push(ary, value);
+
+ return ary;
}
+ */
/*
* X509_ATTRIBUTE init
@@ -184,11 +176,9 @@ Init_ossl_x509attr(VALUE module)
eX509AttributeError = rb_define_class_under(module, "AttributeError", rb_eStandardError);
cX509Attribute = rb_define_class_under(module, "Attribute", rb_cObject);
- rb_define_singleton_method(cX509Attribute, "new", ossl_x509attr_s_new, -1);
- rb_define_method(cX509Attribute, "initialize", ossl_x509attr_initialize, -1);
+ rb_define_singleton_method(cX509Attribute, "new_from_array", ossl_x509attr_s_new_from_array, 1);
/*
* TODO:
- rb_define_method(cX509Attribute, "to_str", ossl_x509attr_to_str, 0);
rb_define_method(cX509Attribute, "to_a", ossl_x509attr_to_a, 0);
*/
}