12 #define NewX509Attr(klass) \ 13 TypedData_Wrap_Struct((klass), &ossl_x509attr_type, 0) 14 #define SetX509Attr(obj, attr) do { \ 16 ossl_raise(rb_eRuntimeError, "ATTR wasn't initialized!"); \ 18 RTYPEDDATA_DATA(obj) = (attr); \ 20 #define GetX509Attr(obj, attr) do { \ 21 TypedData_Get_Struct((obj), X509_ATTRIBUTE, &ossl_x509attr_type, (attr)); \ 23 ossl_raise(rb_eRuntimeError, "ATTR wasn't initialized!"); \ 34 ossl_x509attr_free(
void *ptr)
36 X509_ATTRIBUTE_free(ptr);
40 "OpenSSL/X509/ATTRIBUTE",
42 0, ossl_x509attr_free,
58 new = X509_ATTRIBUTE_new();
60 new = X509_ATTRIBUTE_dup(attr);
84 ossl_x509attr_alloc(
VALUE klass)
90 if (!(attr = X509_ATTRIBUTE_new()))
105 X509_ATTRIBUTE *attr, *x;
106 const unsigned char *p;
113 x = d2i_X509_ATTRIBUTE(&attr, &p,
RSTRING_LEN(oid));
127 ossl_x509attr_initialize_copy(
VALUE self,
VALUE other)
129 X509_ATTRIBUTE *attr, *attr_other, *attr_new;
135 attr_new = X509_ATTRIBUTE_dup(attr_other);
140 X509_ATTRIBUTE_free(attr);
152 X509_ATTRIBUTE *attr;
158 obj = OBJ_txt2obj(s, 0);
160 if (!X509_ATTRIBUTE_set1_object(attr, obj)) {
161 ASN1_OBJECT_free(obj);
164 ASN1_OBJECT_free(obj);
174 ossl_x509attr_get_oid(
VALUE self)
176 X509_ATTRIBUTE *attr;
183 oid = X509_ATTRIBUTE_get0_object(attr);
184 if ((nid = OBJ_obj2nid(oid)) != NID_undef)
187 if (!(out = BIO_new(BIO_s_mem())))
189 i2a_ASN1_OBJECT(out, oid);
201 ossl_x509attr_set_value(
VALUE self,
VALUE value)
203 X509_ATTRIBUTE *attr;
210 if (asn1_tag != V_ASN1_SET)
216 if (X509_ATTRIBUTE_count(attr)) {
217 ASN1_OBJECT *obj = X509_ATTRIBUTE_get0_object(attr);
218 X509_ATTRIBUTE *new_attr = X509_ATTRIBUTE_create_by_OBJ(
NULL, obj, 0,
NULL, -1);
222 X509_ATTRIBUTE_free(attr);
226 for (i = 0; i <
RARRAY_LEN(asn1_value); i++) {
228 if (!X509_ATTRIBUTE_set1_data(attr, ASN1_TYPE_get(a1type),
229 a1type->value.ptr, -1)) {
230 ASN1_TYPE_free(a1type);
233 ASN1_TYPE_free(a1type);
244 ossl_x509attr_get_value(
VALUE self)
246 X509_ATTRIBUTE *attr;
254 if (!(sk = sk_ASN1_TYPE_new_null()))
257 count = X509_ATTRIBUTE_count(attr);
258 for (i = 0; i <
count; i++)
259 sk_ASN1_TYPE_push(sk, X509_ATTRIBUTE_get0_type(attr, i));
261 if ((len = i2d_ASN1_SET_ANY(sk,
NULL)) <= 0) {
262 sk_ASN1_TYPE_free(sk);
267 if (i2d_ASN1_SET_ANY(sk, &p) <= 0) {
268 sk_ASN1_TYPE_free(sk);
272 sk_ASN1_TYPE_free(sk);
282 ossl_x509attr_to_der(
VALUE self)
284 X509_ATTRIBUTE *attr;
290 if((len = i2d_X509_ATTRIBUTE(attr,
NULL)) <= 0)
294 if(i2d_X509_ATTRIBUTE(attr, &p) <= 0)
#define RUBY_TYPED_FREE_IMMEDIATELY
void Init_ossl_x509attr(void)
#define NewX509Attr(klass)
#define ossl_str_adjust(str, p)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE ossl_membio2str(BIO *bio)
#define RB_TYPE_P(obj, type)
VALUE ossl_to_der_if_possible(VALUE obj)
VALUE ossl_x509attr_new(X509_ATTRIBUTE *attr)
RUBY_EXTERN VALUE rb_cObject
STACK_OF(X509) *ossl_x509_ary2sk(VALUE)
#define SetX509Attr(obj, attr)
X509_ATTRIBUTE * GetX509AttrPtr(VALUE obj)
ASN1_TYPE * ossl_asn1_get_asn1type(VALUE obj)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
register unsigned int len
VALUE rb_define_module_under(VALUE outer, const char *name)
#define StringValueCStr(v)
#define RARRAY_AREF(a, i)
#define OSSL_Check_Kind(obj, klass)
void ossl_raise(VALUE exc, const char *fmt,...)
#define rb_check_frozen(obj)
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_attr_get(VALUE, ID)
VALUE rb_str_new(const char *, long)
#define GetX509Attr(obj, attr)