12#define NewX509Name(klass) \
13 TypedData_Wrap_Struct((klass), &ossl_x509name_type, 0)
14#define SetX509Name(obj, name) do { \
16 ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
18 RTYPEDDATA_DATA(obj) = (name); \
20#define GetX509Name(obj, name) do { \
21 TypedData_Get_Struct((obj), X509_NAME, &ossl_x509name_type, (name)); \
23 ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
27#define OBJECT_TYPE_TEMPLATE \
28 rb_const_get(cX509Name, rb_intern("OBJECT_TYPE_TEMPLATE"))
29#define DEFAULT_OBJECT_TYPE \
30 rb_const_get(cX509Name, rb_intern("DEFAULT_OBJECT_TYPE"))
39ossl_x509name_free(
void *
ptr)
47 0, ossl_x509name_free,
63 new = X509_NAME_new();
65 new = X509_NAME_dup(
name);
89ossl_x509name_alloc(
VALUE klass)
95 if (!(
name = X509_NAME_new())) {
105#define rb_aref(obj, key) rb_funcall((obj), id_aref, 1, (key))
118 if(
NIL_P(entry[2])) entry[2] =
rb_aref(
template, entry[0]);
120 ossl_x509name_add_entry(3, entry, self);
164 const unsigned char *p;
181ossl_x509name_initialize_copy(
VALUE self,
VALUE other)
183 X509_NAME *
name, *name_other, *name_new;
189 name_new = X509_NAME_dup(name_other);
194 X509_NAME_free(
name);
223 static ID kwargs_ids[2];
224 const char *oid_name;
225 int loc = -1, set = 0;
227 if (!kwargs_ids[0]) {
228 kwargs_ids[0] = rb_intern_const(
"loc");
229 kwargs_ids[1] = rb_intern_const(
"set");
243 RSTRING_LENINT(value), loc, set))
249ossl_x509name_to_s_old(
VALUE self)
262x509name_print(
VALUE self,
unsigned long iflag)
269 out = BIO_new(BIO_s_mem());
272 ret = X509_NAME_print_ex(
out,
name, 0, iflag);
273 if (ret < 0 || (iflag == XN_FLAG_COMPAT && ret == 0)) {
302 return ossl_x509name_to_s_old(self);
315ossl_x509name_to_utf8(
VALUE self)
317 VALUE str = x509name_print(self, XN_FLAG_RFC2253 & ~ASN1_STRFLGS_ESC_MSB);
324ossl_x509name_inspect(
VALUE self)
338ossl_x509name_to_a(
VALUE self)
341 X509_NAME_ENTRY *entry;
344 const char *short_name;
345 VALUE ary, vname, ret;
349 entries = X509_NAME_entry_count(
name);
355 for (i=0; i<entries; i++) {
356 if (!(entry = X509_NAME_get_entry(
name, i))) {
359 if (!i2t_ASN1_OBJECT(long_name,
sizeof(long_name),
360 X509_NAME_ENTRY_get_object(entry))) {
363 nid = OBJ_ln2nid(long_name);
364 if (
nid == NID_undef) {
367 short_name = OBJ_nid2sn(
nid);
370 value = X509_NAME_ENTRY_get_data(entry);
380 X509_NAME *name1, *name2;
385 return X509_NAME_cmp(name1, name2);
405 result = ossl_x509name_cmp0(self, other);
406 if (result < 0)
return INT2FIX(-1);
407 if (result > 0)
return INT2FIX(1);
424 return ossl_x509name_cmp0(self, other) == 0 ?
Qtrue :
Qfalse;
435ossl_x509name_hash(
VALUE self)
442 hash = X509_NAME_hash(
name);
454ossl_x509name_hash_old(
VALUE self)
461 hash = X509_NAME_hash_old(
name);
473ossl_x509name_to_der(
VALUE self)
485 if(i2d_X509_NAME(
name, &p) <= 0)
510 VALUE utf8str, ptrstr, ia5str, hash;
539 utf8str =
INT2NUM(V_ASN1_UTF8STRING);
540 ptrstr =
INT2NUM(V_ASN1_PRINTABLESTRING);
541 ia5str =
INT2NUM(V_ASN1_IA5STRING);
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_check_array_type(VALUE ary)
VALUE rb_ary_entry(VALUE ary, long offset)
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_utf8_encindex()
rb_encoding * rb_utf8_encoding(void)
VALUE rb_enc_associate_index(VALUE obj, int idx)
char str[HTML_ESCAPE_MAX_LEN+1]
#define RSTRING_LEN(string)
#define RSTRING_PTR(string)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
VALUE rb_define_module_under(VALUE outer, const char *name)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
VALUE rb_cObject
Object class.
VALUE rb_obj_class(VALUE)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
VALUE rb_enc_sprintf(rb_encoding *, const char *,...)
#define rb_str_new(str, len)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
ID rb_intern(const char *)
void rb_define_const(VALUE, const char *, VALUE)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE type(ANYARGS)
ANYARGS-ed function type.
VALUE ossl_buf2str(char *buf, int len)
VALUE ossl_to_der_if_possible(VALUE obj)
void ossl_raise(VALUE exc, const char *fmt,...)
#define ossl_str_adjust(str, p)
VALUE asn1str_to_str(const ASN1_STRING *str)
VALUE ossl_membio2str(BIO *bio)
X509_NAME * GetX509NamePtr(VALUE obj)
#define OBJECT_TYPE_TEMPLATE
#define SetX509Name(obj, name)
void Init_ossl_x509name(void)
VALUE ossl_x509name_new(X509_NAME *name)
#define GetX509Name(obj, name)
#define NewX509Name(klass)
#define DEFAULT_OBJECT_TYPE
#define rb_aref(obj, key)
#define RHASH_SET_IFNONE(h, ifnone)
#define StringValueCStr(v)
@ RUBY_TYPED_FREE_IMMEDIATELY
size_t strlen(const char *)