summaryrefslogtreecommitdiffstats
path: root/OpenSSL/X509/Name.html
blob: b3bf275c4ac18012b7d278f811ec4bbfc3ace08a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::X509::Name - RDoc Documentation</title>

<script type="text/javascript">
  var rdoc_rel_prefix = "../../";
  var index_rel_prefix = "../../";
</script>

<script src="../../js/navigation.js" defer></script>
<script src="../../js/search.js" defer></script>
<script src="../../js/search_index.js" defer></script>
<script src="../../js/searcher.js" defer></script>
<script src="../../js/darkfish.js" defer></script>

<link href="../../css/fonts.css" rel="stylesheet">
<link href="../../css/rdoc.css" rel="stylesheet">


<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../../table_of_contents.html#pages">Pages</a>
    <a href="../../table_of_contents.html#classes">Classes</a>
    <a href="../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

    
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><span class="include">Comparable</span>
    <li><a class="include" href="../Marshal.html">OpenSSL::Marshal</a>
  </ul>
</div>

    
    
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-parse">::parse</a>
    <li ><a href="#method-c-parse_openssl">::parse_openssl</a>
    <li ><a href="#method-c-parse_rfc2253">::parse_rfc2253</a>
    <li ><a href="#method-i-3C-3D-3E">#&lt;=&gt;</a>
    <li ><a href="#method-i-add_entry">#add_entry</a>
    <li ><a href="#method-i-cmp">#cmp</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li ><a href="#method-i-hash">#hash</a>
    <li ><a href="#method-i-hash_old">#hash_old</a>
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    <li ><a href="#method-i-pretty_print">#pretty_print</a>
    <li ><a href="#method-i-to_a">#to_a</a>
    <li ><a href="#method-i-to_der">#to_der</a>
    <li ><a href="#method-i-to_s">#to_s</a>
    <li ><a href="#method-i-to_utf8">#to_utf8</a>
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-OpenSSL::X509::Name">
  <h1 id="class-OpenSSL::X509::Name" class="class">
    class OpenSSL::X509::Name
  </h1>

  <section class="description">
    
<p>An X.509 name represents a hostname, email address or other entity associated with a public key.</p>

<p>You can create a <a href="Name.html"><code>Name</code></a> by parsing a distinguished name String or by supplying the distinguished name as an Array.</p>

<pre class="ruby"><span class="ruby-identifier">name</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Name</span>.<span class="ruby-identifier">parse</span> <span class="ruby-string">&#39;/CN=nobody/DC=example&#39;</span>

<span class="ruby-identifier">name</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span> [[<span class="ruby-string">&#39;CN&#39;</span>, <span class="ruby-string">&#39;nobody&#39;</span>], [<span class="ruby-string">&#39;DC&#39;</span>, <span class="ruby-string">&#39;example&#39;</span>]]
</pre>

  </section>

  <section id="5Buntitled-5D" class="documentation-section">


    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
        <dt id="COMPAT">COMPAT
        <dd><p>A flag for <a href="Name.html#method-i-to_s"><code>to_s</code></a>.</p>

<p>Breaks the name returned into multiple lines if longer than 80 characters.</p>
        <dt id="DEFAULT_OBJECT_TYPE">DEFAULT_OBJECT_TYPE
        <dd><p>The default object type for name entries.</p>
        <dt id="MULTILINE">MULTILINE
        <dd><p>A flag for <a href="Name.html#method-i-to_s"><code>to_s</code></a>.</p>

<p>Returns a multiline format.</p>
        <dt id="OBJECT_TYPE_TEMPLATE">OBJECT_TYPE_TEMPLATE
        <dd><p>The default object type template for name entries.</p>
        <dt id="ONELINE">ONELINE
        <dd><p>A flag for <a href="Name.html#method-i-to_s"><code>to_s</code></a>.</p>

<p>Returns a more readable format than <a href="Name.html#RFC2253"><code>RFC2253</code></a>.</p>
        <dt id="RFC2253">RFC2253
        <dd><p>A flag for <a href="Name.html#method-i-to_s"><code>to_s</code></a>.</p>

<p>Returns an <a href="Name.html#RFC2253"><code>RFC2253</code></a> format name.</p>
      </dl>
    </section>



     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

      <div id="method-c-new" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            X509::Name.new                               &rarr; name
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        <div class="method-heading">
          <span class="method-callseq">
            X509::Name.new(der)                          &rarr; name
          </span>
        </div>
        <div class="method-heading">
          <span class="method-callseq">
            X509::Name.new(distinguished_name)           &rarr; name
          </span>
        </div>
        <div class="method-heading">
          <span class="method-callseq">
            X509::Name.new(distinguished_name, template) &rarr; name
          </span>
        </div>

        <div class="method-description">
          <p>Creates a new <a href="Name.html"><code>Name</code></a>.</p>

<p>A name may be created from a DER encoded string <em>der</em>, an Array representing a <em>distinguished_name</em> or a <em>distinguished_name</em> along with a <em>template</em>.</p>

<pre class="ruby"><span class="ruby-identifier">name</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span> [[<span class="ruby-string">&#39;CN&#39;</span>, <span class="ruby-string">&#39;nobody&#39;</span>], [<span class="ruby-string">&#39;DC&#39;</span>, <span class="ruby-string">&#39;example&#39;</span>]]

<span class="ruby-identifier">name</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_der</span>
</pre>

<p>See <a href="Name.html#method-i-add_entry"><code>add_entry</code></a> for a description of the <em>distinguished_name</em> Array’s contents</p>

          <div class="method-source-code" id="new-source">
            <pre>static VALUE
ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
{
    X509_NAME *name;
    VALUE arg, template;

    GetX509Name(self, name);
    if (rb_scan_args(argc, argv, &quot;02&quot;, &amp;arg, &amp;template) == 0) {
        return self;
    }
    else {
        VALUE tmp = rb_check_array_type(arg);
        if (!NIL_P(tmp)) {
            VALUE args;
            if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE;
            args = rb_ary_new3(2, self, template);
            rb_block_call(tmp, rb_intern(&quot;each&quot;), 0, 0, ossl_x509name_init_i, args);
        }
        else{
            const unsigned char *p;
            VALUE str = ossl_to_der_if_possible(arg);
            X509_NAME *x;
            StringValue(str);
            p = (unsigned char *)RSTRING_PTR(str);
            x = d2i_X509_NAME(&amp;name, &amp;p, RSTRING_LEN(str));
            DATA_PTR(self) = name;
            if(!x){
                ossl_raise(eX509NameError, NULL);
            }
        }
    }

    return self;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-c-parse" class="method-detail method-alias">
        <div class="method-heading">
          <span class="method-name">parse</span><span
            class="method-args">(str, template=OBJECT_TYPE_TEMPLATE)</span>
        </div>

        <div class="method-description">
          

        </div>


        <div class="aliases">
          Alias for: <a href="Name.html#method-c-parse_openssl">parse_openssl</a>
        </div>
      </div>

      <div id="method-c-parse_openssl" class="method-detail ">
        <div class="method-heading">
          <span class="method-name">parse_openssl</span><span
            class="method-args">(str, template=OBJECT_TYPE_TEMPLATE)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          

          <div class="method-source-code" id="parse_openssl-source">
            <pre><span class="ruby-comment"># File lib/openssl/x509.rb, line 287</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parse_openssl</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">template</span>=<span class="ruby-constant">OBJECT_TYPE_TEMPLATE</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">str</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">&quot;/&quot;</span>)
    <span class="ruby-comment"># /A=B/C=D format</span>
    <span class="ruby-identifier">ary</span> = <span class="ruby-identifier">str</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;/&quot;</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;=&quot;</span>, <span class="ruby-value">2</span>) }
  <span class="ruby-keyword">else</span>
    <span class="ruby-comment"># Comma-separated</span>
    <span class="ruby-identifier">ary</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;,&quot;</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;=&quot;</span>, <span class="ruby-value">2</span>) }
  <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ary</span>, <span class="ruby-identifier">template</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
        </div>

        <div class="aliases">
          Also aliased as: <a href="Name.html#method-c-parse">parse</a>
        </div>

      </div>

      <div id="method-c-parse_rfc2253" class="method-detail ">
        <div class="method-heading">
          <span class="method-name">parse_rfc2253</span><span
            class="method-args">(str, template=OBJECT_TYPE_TEMPLATE)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          

          <div class="method-source-code" id="parse_rfc2253-source">
            <pre><span class="ruby-comment"># File lib/openssl/x509.rb, line 282</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parse_rfc2253</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">template</span>=<span class="ruby-constant">OBJECT_TYPE_TEMPLATE</span>)
  <span class="ruby-identifier">ary</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Name</span><span class="ruby-operator">::</span><span class="ruby-constant">RFC2253DN</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">str</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ary</span>, <span class="ruby-identifier">template</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
        </div>


      </div>

    </section>

     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

      <div id="method-i-3C-3D-3E" class="method-detail method-alias">
        <div class="method-heading">
          <span class="method-callseq">
            name &lt;=&gt; other  &rarr; -1 | 0 | 1 | nil
          </span>
        </div>

        <div class="method-description">
          <p>Compares this <a href="Name.html"><code>Name</code></a> with <em>other</em> and returns <code>0</code> if they are the same and <code>-1</code> or <code>+1</code> if they are greater or less than each other respectively. Returns <code>nil</code> if they are not comparable (i.e. different types).</p>

        </div>


        <div class="aliases">
          Alias for: <a href="Name.html#method-i-cmp">cmp</a>
        </div>
      </div>

      <div id="method-i-add_entry" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            add_entry(oid, value [, type], loc: -1, set: 0) &rarr; self
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Adds a new entry with the given <em>oid</em> and <em>value</em> to this name.  The <em>oid</em> is an object identifier defined in ASN.1.  Some common OIDs are:</p>
<dl class="rdoc-list note-list"><dt>C
<dd>
<p>Country <a href="Name.html"><code>Name</code></a></p>
</dd><dt>CN
<dd>
<p>Common <a href="Name.html"><code>Name</code></a></p>
</dd><dt>DC
<dd>
<p>Domain Component</p>
</dd><dt>O
<dd>
<p>Organization <a href="Name.html"><code>Name</code></a></p>
</dd><dt>OU
<dd>
<p>Organizational Unit <a href="Name.html"><code>Name</code></a></p>
</dd><dt>ST
<dd>
<p>State or Province <a href="Name.html"><code>Name</code></a></p>
</dd></dl>

<p>The optional keyword parameters <em>loc</em> and <em>set</em> specify where to insert the new attribute. Refer to the manpage of X509_NAME_add_entry(3) for details. <em>loc</em> defaults to -1 and <em>set</em> defaults to 0. This appends a single-valued RDN to the end.</p>

          <div class="method-source-code" id="add_entry-source">
            <pre>static
VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
{
    X509_NAME *name;
    VALUE oid, value, type, opts, kwargs[2];
    static ID kwargs_ids[2];
    const char *oid_name;
    int loc = -1, set = 0;

    if (!kwargs_ids[0]) {
        kwargs_ids[0] = rb_intern_const(&quot;loc&quot;);
        kwargs_ids[1] = rb_intern_const(&quot;set&quot;);
    }
    rb_scan_args(argc, argv, &quot;21:&quot;, &amp;oid, &amp;value, &amp;type, &amp;opts);
    rb_get_kwargs(opts, kwargs_ids, 0, 2, kwargs);
    oid_name = StringValueCStr(oid);
    StringValue(value);
    if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
    if (kwargs[0] != Qundef)
        loc = NUM2INT(kwargs[0]);
    if (kwargs[1] != Qundef)
        set = NUM2INT(kwargs[1]);
    GetX509Name(self, name);
    if (!X509_NAME_add_entry_by_txt(name, oid_name, NUM2INT(type),
                                    (unsigned char *)RSTRING_PTR(value),
                                    RSTRING_LENINT(value), loc, set))
        ossl_raise(eX509NameError, &quot;X509_NAME_add_entry_by_txt&quot;);
    return self;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-cmp" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            cmp(other) &rarr; -1 | 0 | 1 | nil
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Compares this <a href="Name.html"><code>Name</code></a> with <em>other</em> and returns <code>0</code> if they are the same and <code>-1</code> or <code>+1</code> if they are greater or less than each other respectively. Returns <code>nil</code> if they are not comparable (i.e. different types).</p>

          <div class="method-source-code" id="cmp-source">
            <pre>static VALUE
ossl_x509name_cmp(VALUE self, VALUE other)
{
    int result;

    if (!rb_obj_is_kind_of(other, cX509Name))
        return Qnil;

    result = ossl_x509name_cmp0(self, other);
    if (result &lt; 0) return INT2FIX(-1);
    if (result &gt; 0) return INT2FIX(1);

    return INT2FIX(0);
}</pre>
          </div>
        </div>

        <div class="aliases">
          Also aliased as: <a href="Name.html#method-i-3C-3D-3E">&lt;=&gt;</a>
        </div>

      </div>

      <div id="method-i-eql-3F" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            eql?(other) &rarr; true | false
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns true if <em>name</em> and <em>other</em> refer to the same hash key.</p>

          <div class="method-source-code" id="eql-3F-source">
            <pre>static VALUE
ossl_x509name_eql(VALUE self, VALUE other)
{
    if (!rb_obj_is_kind_of(other, cX509Name))
        return Qfalse;

    return ossl_x509name_cmp0(self, other) == 0 ? Qtrue : Qfalse;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-hash" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            hash &rarr; integer
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>The hash value returned is suitable for use as a certificate’s filename in a CA path.</p>

          <div class="method-source-code" id="hash-source">
            <pre>static VALUE
ossl_x509name_hash(VALUE self)
{
    X509_NAME *name;
    unsigned long hash;

    GetX509Name(self, name);

    hash = X509_NAME_hash(name);

    return ULONG2NUM(hash);
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-hash_old" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            hash_old &rarr; integer
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns an MD5 based hash used in <a href="../../OpenSSL.html"><code>OpenSSL</code></a> 0.9.X.</p>

          <div class="method-source-code" id="hash_old-source">
            <pre>static VALUE
ossl_x509name_hash_old(VALUE self)
{
    X509_NAME *name;
    unsigned long hash;

    GetX509Name(self, name);

    hash = X509_NAME_hash_old(name);

    return ULONG2NUM(hash);
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-initialize_copy" class="method-detail ">
        <div class="method-heading">
          <span class="method-name">initialize_copy</span><span
            class="method-args">(p1)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          

          <div class="method-source-code" id="initialize_copy-source">
            <pre>static VALUE
ossl_x509name_initialize_copy(VALUE self, VALUE other)
{
    X509_NAME *name, *name_other, *name_new;

    rb_check_frozen(self);
    GetX509Name(self, name);
    GetX509Name(other, name_other);

    name_new = X509_NAME_dup(name_other);
    if (!name_new)
        ossl_raise(eX509NameError, &quot;X509_NAME_dup&quot;);

    SetX509Name(self, name_new);
    X509_NAME_free(name);

    return self;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-pretty_print" class="method-detail ">
        <div class="method-heading">
          <span class="method-name">pretty_print</span><span
            class="method-args">(q)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          

          <div class="method-source-code" id="pretty_print-source">
            <pre><span class="ruby-comment"># File lib/openssl/x509.rb, line 301</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">pretty_print</span>(<span class="ruby-identifier">q</span>)
  <span class="ruby-identifier">q</span>.<span class="ruby-identifier">object_group</span>(<span class="ruby-keyword">self</span>) {
    <span class="ruby-identifier">q</span>.<span class="ruby-identifier">text</span> <span class="ruby-string">&#39; &#39;</span>
    <span class="ruby-identifier">q</span>.<span class="ruby-identifier">text</span> <span class="ruby-identifier">to_s</span>(<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Name</span><span class="ruby-operator">::</span><span class="ruby-constant">RFC2253</span>)
  }
<span class="ruby-keyword">end</span></pre>
          </div>
        </div>


      </div>

      <div id="method-i-to_a" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            to_a &rarr; [[name, data, type], ...]
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns an Array representation of the distinguished name suitable for passing to <a href="Name.html#method-c-new"><code>::new</code></a></p>

          <div class="method-source-code" id="to_a-source">
            <pre>static VALUE
ossl_x509name_to_a(VALUE self)
{
    X509_NAME *name;
    X509_NAME_ENTRY *entry;
    int i,entries,nid;
    char long_name[512];
    const char *short_name;
    VALUE ary, vname, ret;
    ASN1_STRING *value;

    GetX509Name(self, name);
    entries = X509_NAME_entry_count(name);
    if (entries &lt; 0) {
        OSSL_Debug(&quot;name entries &lt; 0!&quot;);
        return rb_ary_new();
    }
    ret = rb_ary_new2(entries);
    for (i=0; i&lt;entries; i++) {
        if (!(entry = X509_NAME_get_entry(name, i))) {
            ossl_raise(eX509NameError, NULL);
        }
        if (!i2t_ASN1_OBJECT(long_name, sizeof(long_name),
                             X509_NAME_ENTRY_get_object(entry))) {
            ossl_raise(eX509NameError, NULL);
        }
        nid = OBJ_ln2nid(long_name);
        if (nid == NID_undef) {
            vname = rb_str_new2((const char *) &amp;long_name);
        } else {
            short_name = OBJ_nid2sn(nid);
            vname = rb_str_new2(short_name); /*do not free*/
        }
        value = X509_NAME_ENTRY_get_data(entry);
        ary = rb_ary_new3(3, vname, asn1str_to_str(value), INT2NUM(value-&gt;type));
        rb_ary_push(ret, ary);
    }
    return ret;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-to_der" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            to_der &rarr; string
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Converts the name to DER encoding</p>

          <div class="method-source-code" id="to_der-source">
            <pre>static VALUE
ossl_x509name_to_der(VALUE self)
{
    X509_NAME *name;
    VALUE str;
    long len;
    unsigned char *p;

    GetX509Name(self, name);
    if((len = i2d_X509_NAME(name, NULL)) &lt;= 0)
        ossl_raise(eX509NameError, NULL);
    str = rb_str_new(0, len);
    p = (unsigned char *)RSTRING_PTR(str);
    if(i2d_X509_NAME(name, &amp;p) &lt;= 0)
        ossl_raise(eX509NameError, NULL);
    ossl_str_adjust(str, p);

    return str;
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-to_s" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            to_s         &rarr; string
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        <div class="method-heading">
          <span class="method-callseq">
            to_s(format) &rarr; string
          </span>
        </div>

        <div class="method-description">
          <p>Returns a String representation of the Distinguished <a href="Name.html"><code>Name</code></a>. <em>format</em> is one of:</p>
<ul><li>
<p><a href="Name.html#COMPAT"><code>OpenSSL::X509::Name::COMPAT</code></a></p>
</li><li>
<p><a href="Name.html#RFC2253"><code>OpenSSL::X509::Name::RFC2253</code></a></p>
</li><li>
<p><a href="Name.html#ONELINE"><code>OpenSSL::X509::Name::ONELINE</code></a></p>
</li><li>
<p><a href="Name.html#MULTILINE"><code>OpenSSL::X509::Name::MULTILINE</code></a></p>
</li></ul>

<p>If <em>format</em> is omitted, the largely broken and traditional <a href="../../OpenSSL.html"><code>OpenSSL</code></a> format is used.</p>

          <div class="method-source-code" id="to_s-source">
            <pre>static VALUE
ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
{
    rb_check_arity(argc, 0, 1);
    /* name.to_s(nil) was allowed */
    if (!argc || NIL_P(argv[0]))
        return ossl_x509name_to_s_old(self);
    else
        return x509name_print(self, NUM2ULONG(argv[0]));
}</pre>
          </div>
        </div>


      </div>

      <div id="method-i-to_utf8" class="method-detail ">
        <div class="method-heading">
          <span class="method-callseq">
            to_utf8 &rarr; string
          </span>
          <span class="method-click-advice">click to toggle source</span>
        </div>

        <div class="method-description">
          <p>Returns an UTF-8 representation of the distinguished name, as specified in <a href="https://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a>.</p>

          <div class="method-source-code" id="to_utf8-source">
            <pre>static VALUE
ossl_x509name_to_utf8(VALUE self)
{
    VALUE str = x509name_print(self, XN_FLAG_RFC2253 &amp; ~ASN1_STRFLGS_ESC_MSB);
    rb_enc_associate_index(str, rb_utf8_encindex());
    return str;
}</pre>
          </div>
        </div>


      </div>

    </section>

  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.3.2.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>