zig_example 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/ext/mkmf.rb +2734 -0
  3. data/ext/openssl/openssl_missing.c +40 -0
  4. data/ext/openssl/openssl_missing.h +238 -0
  5. data/ext/openssl/ossl.c +1295 -0
  6. data/ext/openssl/ossl.h +201 -0
  7. data/ext/openssl/ossl_asn1.c +1891 -0
  8. data/ext/openssl/ossl_asn1.h +62 -0
  9. data/ext/openssl/ossl_bio.c +42 -0
  10. data/ext/openssl/ossl_bio.h +16 -0
  11. data/ext/openssl/ossl_bn.c +1344 -0
  12. data/ext/openssl/ossl_bn.h +26 -0
  13. data/ext/openssl/ossl_cipher.c +1074 -0
  14. data/ext/openssl/ossl_cipher.h +20 -0
  15. data/ext/openssl/ossl_config.c +460 -0
  16. data/ext/openssl/ossl_config.h +16 -0
  17. data/ext/openssl/ossl_digest.c +425 -0
  18. data/ext/openssl/ossl_digest.h +20 -0
  19. data/ext/openssl/ossl_engine.c +568 -0
  20. data/ext/openssl/ossl_engine.h +19 -0
  21. data/ext/openssl/ossl_hmac.c +310 -0
  22. data/ext/openssl/ossl_hmac.h +18 -0
  23. data/ext/openssl/ossl_kdf.c +311 -0
  24. data/ext/openssl/ossl_kdf.h +6 -0
  25. data/ext/openssl/ossl_ns_spki.c +405 -0
  26. data/ext/openssl/ossl_ns_spki.h +19 -0
  27. data/ext/openssl/ossl_ocsp.c +1965 -0
  28. data/ext/openssl/ossl_ocsp.h +23 -0
  29. data/ext/openssl/ossl_pkcs12.c +275 -0
  30. data/ext/openssl/ossl_pkcs12.h +13 -0
  31. data/ext/openssl/ossl_pkcs7.c +1081 -0
  32. data/ext/openssl/ossl_pkcs7.h +36 -0
  33. data/ext/openssl/ossl_pkey.c +1624 -0
  34. data/ext/openssl/ossl_pkey.h +204 -0
  35. data/ext/openssl/ossl_pkey_dh.c +440 -0
  36. data/ext/openssl/ossl_pkey_dsa.c +359 -0
  37. data/ext/openssl/ossl_pkey_ec.c +1655 -0
  38. data/ext/openssl/ossl_pkey_rsa.c +579 -0
  39. data/ext/openssl/ossl_rand.c +200 -0
  40. data/ext/openssl/ossl_rand.h +18 -0
  41. data/ext/openssl/ossl_ssl.c +3142 -0
  42. data/ext/openssl/ossl_ssl.h +36 -0
  43. data/ext/openssl/ossl_ssl_session.c +331 -0
  44. data/ext/openssl/ossl_ts.c +1539 -0
  45. data/ext/openssl/ossl_ts.h +16 -0
  46. data/ext/openssl/ossl_x509.c +256 -0
  47. data/ext/openssl/ossl_x509.h +115 -0
  48. data/ext/openssl/ossl_x509attr.c +324 -0
  49. data/ext/openssl/ossl_x509cert.c +1002 -0
  50. data/ext/openssl/ossl_x509crl.c +545 -0
  51. data/ext/openssl/ossl_x509ext.c +490 -0
  52. data/ext/openssl/ossl_x509name.c +597 -0
  53. data/ext/openssl/ossl_x509req.c +444 -0
  54. data/ext/openssl/ossl_x509revoked.c +300 -0
  55. data/ext/openssl/ossl_x509store.c +986 -0
  56. data/ext/zigrb_100doors/build.zig +0 -12
  57. data/ext/zigrb_100doors/extconf.rb +2 -19
  58. data/ext/zigrb_ackermann/build.zig +0 -12
  59. data/ext/zigrb_ackermann/extconf.rb +2 -19
  60. data/ext/zigrb_lucas_lehmer/build.zig +53 -0
  61. data/ext/zigrb_lucas_lehmer/extconf.rb +3 -0
  62. data/ext/zigrb_lucas_lehmer/src/lucas_lehmer.c +60 -0
  63. data/ext/zigrb_lucas_lehmer/src/lucas_lehmer.h +1 -0
  64. data/ext/zigrb_lucas_lehmer/src/wrapper.zig +42 -0
  65. data/lib/zig_example/version.rb +1 -1
  66. data/lib/zig_example.rb +1 -0
  67. metadata +63 -3
@@ -0,0 +1,597 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ * All rights reserved.
5
+ */
6
+ /*
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #include "ossl.h"
11
+
12
+ #define NewX509Name(klass) \
13
+ TypedData_Wrap_Struct((klass), &ossl_x509name_type, 0)
14
+ #define SetX509Name(obj, name) do { \
15
+ if (!(name)) { \
16
+ ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
17
+ } \
18
+ RTYPEDDATA_DATA(obj) = (name); \
19
+ } while (0)
20
+ #define GetX509Name(obj, name) do { \
21
+ TypedData_Get_Struct((obj), X509_NAME, &ossl_x509name_type, (name)); \
22
+ if (!(name)) { \
23
+ ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
24
+ } \
25
+ } while (0)
26
+
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"))
31
+
32
+ /*
33
+ * Classes
34
+ */
35
+ VALUE cX509Name;
36
+ VALUE eX509NameError;
37
+
38
+ static void
39
+ ossl_x509name_free(void *ptr)
40
+ {
41
+ X509_NAME_free(ptr);
42
+ }
43
+
44
+ static const rb_data_type_t ossl_x509name_type = {
45
+ "OpenSSL/X509/NAME",
46
+ {
47
+ 0, ossl_x509name_free,
48
+ },
49
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
50
+ };
51
+
52
+ /*
53
+ * Public
54
+ */
55
+ VALUE
56
+ ossl_x509name_new(X509_NAME *name)
57
+ {
58
+ X509_NAME *new;
59
+ VALUE obj;
60
+
61
+ obj = NewX509Name(cX509Name);
62
+ if (!name) {
63
+ new = X509_NAME_new();
64
+ } else {
65
+ new = X509_NAME_dup(name);
66
+ }
67
+ if (!new) {
68
+ ossl_raise(eX509NameError, NULL);
69
+ }
70
+ SetX509Name(obj, new);
71
+
72
+ return obj;
73
+ }
74
+
75
+ X509_NAME *
76
+ GetX509NamePtr(VALUE obj)
77
+ {
78
+ X509_NAME *name;
79
+
80
+ GetX509Name(obj, name);
81
+
82
+ return name;
83
+ }
84
+
85
+ /*
86
+ * Private
87
+ */
88
+ static VALUE
89
+ ossl_x509name_alloc(VALUE klass)
90
+ {
91
+ X509_NAME *name;
92
+ VALUE obj;
93
+
94
+ obj = NewX509Name(klass);
95
+ if (!(name = X509_NAME_new())) {
96
+ ossl_raise(eX509NameError, NULL);
97
+ }
98
+ SetX509Name(obj, name);
99
+
100
+ return obj;
101
+ }
102
+
103
+ static ID id_aref;
104
+ static VALUE ossl_x509name_add_entry(int, VALUE*, VALUE);
105
+ #define rb_aref(obj, key) rb_funcall((obj), id_aref, 1, (key))
106
+
107
+ static VALUE
108
+ ossl_x509name_init_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
109
+ {
110
+ VALUE self = rb_ary_entry(args, 0);
111
+ VALUE template = rb_ary_entry(args, 1);
112
+ VALUE entry[3];
113
+
114
+ Check_Type(i, T_ARRAY);
115
+ entry[0] = rb_ary_entry(i, 0);
116
+ entry[1] = rb_ary_entry(i, 1);
117
+ entry[2] = rb_ary_entry(i, 2);
118
+ if(NIL_P(entry[2])) entry[2] = rb_aref(template, entry[0]);
119
+ if(NIL_P(entry[2])) entry[2] = DEFAULT_OBJECT_TYPE;
120
+ ossl_x509name_add_entry(3, entry, self);
121
+
122
+ return Qnil;
123
+ }
124
+
125
+ /*
126
+ * call-seq:
127
+ * X509::Name.new => name
128
+ * X509::Name.new(der) => name
129
+ * X509::Name.new(distinguished_name) => name
130
+ * X509::Name.new(distinguished_name, template) => name
131
+ *
132
+ * Creates a new Name.
133
+ *
134
+ * A name may be created from a DER encoded string _der_, an Array
135
+ * representing a _distinguished_name_ or a _distinguished_name_ along with a
136
+ * _template_.
137
+ *
138
+ * name = OpenSSL::X509::Name.new [['CN', 'nobody'], ['DC', 'example']]
139
+ *
140
+ * name = OpenSSL::X509::Name.new name.to_der
141
+ *
142
+ * See add_entry for a description of the _distinguished_name_ Array's
143
+ * contents
144
+ */
145
+ static VALUE
146
+ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
147
+ {
148
+ X509_NAME *name;
149
+ VALUE arg, template;
150
+
151
+ GetX509Name(self, name);
152
+ if (rb_scan_args(argc, argv, "02", &arg, &template) == 0) {
153
+ return self;
154
+ }
155
+ else {
156
+ VALUE tmp = rb_check_array_type(arg);
157
+ if (!NIL_P(tmp)) {
158
+ VALUE args;
159
+ if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE;
160
+ args = rb_ary_new3(2, self, template);
161
+ rb_block_call(tmp, rb_intern("each"), 0, 0, ossl_x509name_init_i, args);
162
+ }
163
+ else{
164
+ const unsigned char *p;
165
+ VALUE str = ossl_to_der_if_possible(arg);
166
+ X509_NAME *x;
167
+ StringValue(str);
168
+ p = (unsigned char *)RSTRING_PTR(str);
169
+ x = d2i_X509_NAME(&name, &p, RSTRING_LEN(str));
170
+ DATA_PTR(self) = name;
171
+ if(!x){
172
+ ossl_raise(eX509NameError, NULL);
173
+ }
174
+ }
175
+ }
176
+
177
+ return self;
178
+ }
179
+
180
+ static VALUE
181
+ ossl_x509name_initialize_copy(VALUE self, VALUE other)
182
+ {
183
+ X509_NAME *name, *name_other, *name_new;
184
+
185
+ rb_check_frozen(self);
186
+ GetX509Name(self, name);
187
+ GetX509Name(other, name_other);
188
+
189
+ name_new = X509_NAME_dup(name_other);
190
+ if (!name_new)
191
+ ossl_raise(eX509NameError, "X509_NAME_dup");
192
+
193
+ SetX509Name(self, name_new);
194
+ X509_NAME_free(name);
195
+
196
+ return self;
197
+ }
198
+
199
+ /*
200
+ * call-seq:
201
+ * name.add_entry(oid, value [, type], loc: -1, set: 0) => self
202
+ *
203
+ * Adds a new entry with the given _oid_ and _value_ to this name. The _oid_
204
+ * is an object identifier defined in ASN.1. Some common OIDs are:
205
+ *
206
+ * C:: Country Name
207
+ * CN:: Common Name
208
+ * DC:: Domain Component
209
+ * O:: Organization Name
210
+ * OU:: Organizational Unit Name
211
+ * ST:: State or Province Name
212
+ *
213
+ * The optional keyword parameters _loc_ and _set_ specify where to insert the
214
+ * new attribute. Refer to the manpage of X509_NAME_add_entry(3) for details.
215
+ * _loc_ defaults to -1 and _set_ defaults to 0. This appends a single-valued
216
+ * RDN to the end.
217
+ */
218
+ static
219
+ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
220
+ {
221
+ X509_NAME *name;
222
+ VALUE oid, value, type, opts, kwargs[2];
223
+ static ID kwargs_ids[2];
224
+ const char *oid_name;
225
+ int loc = -1, set = 0;
226
+
227
+ if (!kwargs_ids[0]) {
228
+ kwargs_ids[0] = rb_intern_const("loc");
229
+ kwargs_ids[1] = rb_intern_const("set");
230
+ }
231
+ rb_scan_args(argc, argv, "21:", &oid, &value, &type, &opts);
232
+ rb_get_kwargs(opts, kwargs_ids, 0, 2, kwargs);
233
+ oid_name = StringValueCStr(oid);
234
+ StringValue(value);
235
+ if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
236
+ if (kwargs[0] != Qundef)
237
+ loc = NUM2INT(kwargs[0]);
238
+ if (kwargs[1] != Qundef)
239
+ set = NUM2INT(kwargs[1]);
240
+ GetX509Name(self, name);
241
+ if (!X509_NAME_add_entry_by_txt(name, oid_name, NUM2INT(type),
242
+ (unsigned char *)RSTRING_PTR(value),
243
+ RSTRING_LENINT(value), loc, set))
244
+ ossl_raise(eX509NameError, "X509_NAME_add_entry_by_txt");
245
+ return self;
246
+ }
247
+
248
+ static VALUE
249
+ ossl_x509name_to_s_old(VALUE self)
250
+ {
251
+ X509_NAME *name;
252
+ char *buf;
253
+
254
+ GetX509Name(self, name);
255
+ buf = X509_NAME_oneline(name, NULL, 0);
256
+ if (!buf)
257
+ ossl_raise(eX509NameError, "X509_NAME_oneline");
258
+ return ossl_buf2str(buf, rb_long2int(strlen(buf)));
259
+ }
260
+
261
+ static VALUE
262
+ x509name_print(VALUE self, unsigned long iflag)
263
+ {
264
+ X509_NAME *name;
265
+ BIO *out;
266
+ int ret;
267
+
268
+ GetX509Name(self, name);
269
+ out = BIO_new(BIO_s_mem());
270
+ if (!out)
271
+ ossl_raise(eX509NameError, NULL);
272
+ ret = X509_NAME_print_ex(out, name, 0, iflag);
273
+ if (ret < 0 || (iflag == XN_FLAG_COMPAT && ret == 0)) {
274
+ BIO_free(out);
275
+ ossl_raise(eX509NameError, "X509_NAME_print_ex");
276
+ }
277
+ return ossl_membio2str(out);
278
+ }
279
+
280
+ /*
281
+ * call-seq:
282
+ * name.to_s -> string
283
+ * name.to_s(format) -> string
284
+ *
285
+ * Returns a String representation of the Distinguished Name. _format_ is
286
+ * one of:
287
+ *
288
+ * * OpenSSL::X509::Name::COMPAT
289
+ * * OpenSSL::X509::Name::RFC2253
290
+ * * OpenSSL::X509::Name::ONELINE
291
+ * * OpenSSL::X509::Name::MULTILINE
292
+ *
293
+ * If _format_ is omitted, the largely broken and traditional OpenSSL format
294
+ * (<tt>X509_NAME_oneline()</tt> format) is chosen.
295
+ *
296
+ * <b>Use of this method is discouraged.</b> None of the formats other than
297
+ * OpenSSL::X509::Name::RFC2253 is standardized and may show an inconsistent
298
+ * behavior through \OpenSSL versions.
299
+ *
300
+ * It is recommended to use #to_utf8 instead, which is equivalent to calling
301
+ * <tt>name.to_s(OpenSSL::X509::Name::RFC2253).force_encoding("UTF-8")</tt>.
302
+ */
303
+ static VALUE
304
+ ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
305
+ {
306
+ rb_check_arity(argc, 0, 1);
307
+ /* name.to_s(nil) was allowed */
308
+ if (!argc || NIL_P(argv[0]))
309
+ return ossl_x509name_to_s_old(self);
310
+ else
311
+ return x509name_print(self, NUM2ULONG(argv[0]));
312
+ }
313
+
314
+ /*
315
+ * call-seq:
316
+ * name.to_utf8 -> string
317
+ *
318
+ * Returns an UTF-8 representation of the distinguished name, as specified
319
+ * in {RFC 2253}[https://www.ietf.org/rfc/rfc2253.txt].
320
+ */
321
+ static VALUE
322
+ ossl_x509name_to_utf8(VALUE self)
323
+ {
324
+ VALUE str = x509name_print(self, XN_FLAG_RFC2253 & ~ASN1_STRFLGS_ESC_MSB);
325
+ rb_enc_associate_index(str, rb_utf8_encindex());
326
+ return str;
327
+ }
328
+
329
+ /* :nodoc: */
330
+ static VALUE
331
+ ossl_x509name_inspect(VALUE self)
332
+ {
333
+ return rb_enc_sprintf(rb_utf8_encoding(), "#<%"PRIsVALUE" %"PRIsVALUE">",
334
+ rb_obj_class(self), ossl_x509name_to_utf8(self));
335
+ }
336
+
337
+ /*
338
+ * call-seq:
339
+ * name.to_a => [[name, data, type], ...]
340
+ *
341
+ * Returns an Array representation of the distinguished name suitable for
342
+ * passing to ::new
343
+ */
344
+ static VALUE
345
+ ossl_x509name_to_a(VALUE self)
346
+ {
347
+ X509_NAME *name;
348
+ X509_NAME_ENTRY *entry;
349
+ int i,entries,nid;
350
+ char long_name[512];
351
+ const char *short_name;
352
+ VALUE ary, vname, ret;
353
+ ASN1_STRING *value;
354
+
355
+ GetX509Name(self, name);
356
+ entries = X509_NAME_entry_count(name);
357
+ if (entries < 0) {
358
+ OSSL_Debug("name entries < 0!");
359
+ return rb_ary_new();
360
+ }
361
+ ret = rb_ary_new2(entries);
362
+ for (i=0; i<entries; i++) {
363
+ if (!(entry = X509_NAME_get_entry(name, i))) {
364
+ ossl_raise(eX509NameError, NULL);
365
+ }
366
+ if (!i2t_ASN1_OBJECT(long_name, sizeof(long_name),
367
+ X509_NAME_ENTRY_get_object(entry))) {
368
+ ossl_raise(eX509NameError, NULL);
369
+ }
370
+ nid = OBJ_ln2nid(long_name);
371
+ if (nid == NID_undef) {
372
+ vname = rb_str_new2((const char *) &long_name);
373
+ } else {
374
+ short_name = OBJ_nid2sn(nid);
375
+ vname = rb_str_new2(short_name); /*do not free*/
376
+ }
377
+ value = X509_NAME_ENTRY_get_data(entry);
378
+ ary = rb_ary_new3(3, vname, asn1str_to_str(value), INT2NUM(value->type));
379
+ rb_ary_push(ret, ary);
380
+ }
381
+ return ret;
382
+ }
383
+
384
+ static int
385
+ ossl_x509name_cmp0(VALUE self, VALUE other)
386
+ {
387
+ X509_NAME *name1, *name2;
388
+
389
+ GetX509Name(self, name1);
390
+ GetX509Name(other, name2);
391
+
392
+ return X509_NAME_cmp(name1, name2);
393
+ }
394
+
395
+ /*
396
+ * call-seq:
397
+ * name.cmp(other) -> -1 | 0 | 1 | nil
398
+ * name <=> other -> -1 | 0 | 1 | nil
399
+ *
400
+ * Compares this Name with _other_ and returns +0+ if they are the same and +-1+
401
+ * or ++1+ if they are greater or less than each other respectively.
402
+ * Returns +nil+ if they are not comparable (i.e. different types).
403
+ */
404
+ static VALUE
405
+ ossl_x509name_cmp(VALUE self, VALUE other)
406
+ {
407
+ int result;
408
+
409
+ if (!rb_obj_is_kind_of(other, cX509Name))
410
+ return Qnil;
411
+
412
+ result = ossl_x509name_cmp0(self, other);
413
+ if (result < 0) return INT2FIX(-1);
414
+ if (result > 0) return INT2FIX(1);
415
+
416
+ return INT2FIX(0);
417
+ }
418
+
419
+ /*
420
+ * call-seq:
421
+ * name.eql?(other) -> true | false
422
+ *
423
+ * Returns true if _name_ and _other_ refer to the same hash key.
424
+ */
425
+ static VALUE
426
+ ossl_x509name_eql(VALUE self, VALUE other)
427
+ {
428
+ if (!rb_obj_is_kind_of(other, cX509Name))
429
+ return Qfalse;
430
+
431
+ return ossl_x509name_cmp0(self, other) == 0 ? Qtrue : Qfalse;
432
+ }
433
+
434
+ /*
435
+ * call-seq:
436
+ * name.hash => integer
437
+ *
438
+ * The hash value returned is suitable for use as a certificate's filename in
439
+ * a CA path.
440
+ */
441
+ static VALUE
442
+ ossl_x509name_hash(VALUE self)
443
+ {
444
+ X509_NAME *name;
445
+ unsigned long hash;
446
+
447
+ GetX509Name(self, name);
448
+
449
+ hash = X509_NAME_hash(name);
450
+
451
+ return ULONG2NUM(hash);
452
+ }
453
+
454
+ /*
455
+ * call-seq:
456
+ * name.hash_old => integer
457
+ *
458
+ * Returns an MD5 based hash used in OpenSSL 0.9.X.
459
+ */
460
+ static VALUE
461
+ ossl_x509name_hash_old(VALUE self)
462
+ {
463
+ X509_NAME *name;
464
+ unsigned long hash;
465
+
466
+ GetX509Name(self, name);
467
+
468
+ hash = X509_NAME_hash_old(name);
469
+
470
+ return ULONG2NUM(hash);
471
+ }
472
+
473
+ /*
474
+ * call-seq:
475
+ * name.to_der => string
476
+ *
477
+ * Converts the name to DER encoding
478
+ */
479
+ static VALUE
480
+ ossl_x509name_to_der(VALUE self)
481
+ {
482
+ X509_NAME *name;
483
+ VALUE str;
484
+ long len;
485
+ unsigned char *p;
486
+
487
+ GetX509Name(self, name);
488
+ if((len = i2d_X509_NAME(name, NULL)) <= 0)
489
+ ossl_raise(eX509NameError, NULL);
490
+ str = rb_str_new(0, len);
491
+ p = (unsigned char *)RSTRING_PTR(str);
492
+ if(i2d_X509_NAME(name, &p) <= 0)
493
+ ossl_raise(eX509NameError, NULL);
494
+ ossl_str_adjust(str, p);
495
+
496
+ return str;
497
+ }
498
+
499
+ /*
500
+ * Document-class: OpenSSL::X509::Name
501
+ *
502
+ * An X.509 name represents a hostname, email address or other entity
503
+ * associated with a public key.
504
+ *
505
+ * You can create a Name by parsing a distinguished name String or by
506
+ * supplying the distinguished name as an Array.
507
+ *
508
+ * name = OpenSSL::X509::Name.parse_rfc2253 'DC=example,CN=nobody'
509
+ *
510
+ * name = OpenSSL::X509::Name.new [['CN', 'nobody'], ['DC', 'example']]
511
+ */
512
+
513
+ void
514
+ Init_ossl_x509name(void)
515
+ {
516
+ #undef rb_intern
517
+ VALUE utf8str, ptrstr, ia5str, hash;
518
+
519
+ #if 0
520
+ mOSSL = rb_define_module("OpenSSL");
521
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
522
+ mX509 = rb_define_module_under(mOSSL, "X509");
523
+ #endif
524
+
525
+ id_aref = rb_intern("[]");
526
+ eX509NameError = rb_define_class_under(mX509, "NameError", eOSSLError);
527
+ cX509Name = rb_define_class_under(mX509, "Name", rb_cObject);
528
+
529
+ rb_include_module(cX509Name, rb_mComparable);
530
+
531
+ rb_define_alloc_func(cX509Name, ossl_x509name_alloc);
532
+ rb_define_method(cX509Name, "initialize", ossl_x509name_initialize, -1);
533
+ rb_define_method(cX509Name, "initialize_copy", ossl_x509name_initialize_copy, 1);
534
+ rb_define_method(cX509Name, "add_entry", ossl_x509name_add_entry, -1);
535
+ rb_define_method(cX509Name, "to_s", ossl_x509name_to_s, -1);
536
+ rb_define_method(cX509Name, "to_utf8", ossl_x509name_to_utf8, 0);
537
+ rb_define_method(cX509Name, "inspect", ossl_x509name_inspect, 0);
538
+ rb_define_method(cX509Name, "to_a", ossl_x509name_to_a, 0);
539
+ rb_define_method(cX509Name, "cmp", ossl_x509name_cmp, 1);
540
+ rb_define_alias(cX509Name, "<=>", "cmp");
541
+ rb_define_method(cX509Name, "eql?", ossl_x509name_eql, 1);
542
+ rb_define_method(cX509Name, "hash", ossl_x509name_hash, 0);
543
+ rb_define_method(cX509Name, "hash_old", ossl_x509name_hash_old, 0);
544
+ rb_define_method(cX509Name, "to_der", ossl_x509name_to_der, 0);
545
+
546
+ utf8str = INT2NUM(V_ASN1_UTF8STRING);
547
+ ptrstr = INT2NUM(V_ASN1_PRINTABLESTRING);
548
+ ia5str = INT2NUM(V_ASN1_IA5STRING);
549
+
550
+ /*
551
+ * The default object type for name entries.
552
+ */
553
+ rb_define_const(cX509Name, "DEFAULT_OBJECT_TYPE", utf8str);
554
+ hash = rb_hash_new();
555
+ RHASH_SET_IFNONE(hash, utf8str);
556
+ rb_hash_aset(hash, rb_str_new2("C"), ptrstr);
557
+ rb_hash_aset(hash, rb_str_new2("countryName"), ptrstr);
558
+ rb_hash_aset(hash, rb_str_new2("serialNumber"), ptrstr);
559
+ rb_hash_aset(hash, rb_str_new2("dnQualifier"), ptrstr);
560
+ rb_hash_aset(hash, rb_str_new2("DC"), ia5str);
561
+ rb_hash_aset(hash, rb_str_new2("domainComponent"), ia5str);
562
+ rb_hash_aset(hash, rb_str_new2("emailAddress"), ia5str);
563
+
564
+ /*
565
+ * The default object type template for name entries.
566
+ */
567
+ rb_define_const(cX509Name, "OBJECT_TYPE_TEMPLATE", hash);
568
+
569
+ /*
570
+ * A flag for #to_s.
571
+ *
572
+ * Breaks the name returned into multiple lines if longer than 80
573
+ * characters.
574
+ */
575
+ rb_define_const(cX509Name, "COMPAT", ULONG2NUM(XN_FLAG_COMPAT));
576
+
577
+ /*
578
+ * A flag for #to_s.
579
+ *
580
+ * Returns an RFC2253 format name.
581
+ */
582
+ rb_define_const(cX509Name, "RFC2253", ULONG2NUM(XN_FLAG_RFC2253));
583
+
584
+ /*
585
+ * A flag for #to_s.
586
+ *
587
+ * Returns a more readable format than RFC2253.
588
+ */
589
+ rb_define_const(cX509Name, "ONELINE", ULONG2NUM(XN_FLAG_ONELINE));
590
+
591
+ /*
592
+ * A flag for #to_s.
593
+ *
594
+ * Returns a multiline format.
595
+ */
596
+ rb_define_const(cX509Name, "MULTILINE", ULONG2NUM(XN_FLAG_MULTILINE));
597
+ }