File: UserKeyManager.html

package info (click to toggle)
libnet-ssh-ruby 1.0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,180 kB
  • ctags: 2,327
  • sloc: ruby: 10,321; makefile: 52
file content (630 lines) | stat: -rw-r--r-- 30,288 bytes parent folder | download
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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Net::SSH::UserAuth::UserKeyManager</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Net::SSH::UserAuth::UserKeyManager</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/lib/net/ssh/userauth/userkeys_rb.html">
                lib/net/ssh/userauth/userkeys.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
This class encapsulates all operations done by clients on a user&#8217;s
private keys. In practice, the client should never need a reference to a
private key; instead, they grab a list of &quot;identities&quot; (public
keys) that are available from the <a
href="UserKeyManager.html">UserKeyManager</a>, and then use the <a
href="UserKeyManager.html">UserKeyManager</a> to do various private key
operations using those identities.
</p>
<p>
The <a href="UserKeyManager.html">UserKeyManager</a> also uses the <a
href="Agent.html">Agent</a> class to encapsulate the ssh-agent. Thus, from
a client&#8217;s perspective it is completely hidden whether an identity
comes from the ssh-agent or from a file on disk.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000148">&lt;&lt;</a>&nbsp;&nbsp;
      <a href="#M000147">add</a>&nbsp;&nbsp;
      <a href="#M000149">add_host_key</a>&nbsp;&nbsp;
      <a href="#M000145">clear!</a>&nbsp;&nbsp;
      <a href="#M000146">clear_host!</a>&nbsp;&nbsp;
      <a href="#M000150">finish</a>&nbsp;&nbsp;
      <a href="#M000152">host_identities</a>&nbsp;&nbsp;
      <a href="#M000151">identities</a>&nbsp;&nbsp;
      <a href="#M000144">new</a>&nbsp;&nbsp;
      <a href="#M000153">sign</a>&nbsp;&nbsp;
      <a href="#M000155">use_agent=</a>&nbsp;&nbsp;
      <a href="#M000154">use_agent?</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">agent_factory</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc">
The agent factory to use when a new agent instance is needed.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">buffers</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc">
The buffer manager to use for providing new buffer instances.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">host_key_files</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The list of host key files that will be examined

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">key_existence_tester</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc">
The object that will be used to test whether a given key file is readable.
This object must only respond to &quot;readable?&quot; with one parameter,
the file to test the readability of.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">key_files</td>
          <td class="context-item-value">&nbsp;[R]&nbsp;</td>
          <td class="context-item-desc">
The list of user key files that will be examined

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">keys</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc">
The key manager instance to use for managing keys

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">log</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc">
The logger instance to use for logging messages

</td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000144" class="method-detail">
        <a name="M000144"></a>

        <div class="method-heading">
          <a href="#M000144" class="method-signature">
          <span class="method-name">new</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a new <a href="UserKeyManager.html">UserKeyManager</a>. By default,
the manager will use the ssh-agent (if it is running).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000144-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000144-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 64</span>
64:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
65:           <span class="ruby-ivar">@key_files</span> = []
66:           <span class="ruby-ivar">@host_key_files</span> = []
67:           <span class="ruby-ivar">@use_agent</span> = <span class="ruby-keyword kw">true</span>
68:           <span class="ruby-ivar">@agent</span> = <span class="ruby-keyword kw">nil</span>
69:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000148" class="method-detail">
        <a name="M000148"></a>

        <div class="method-heading">
          <span class="method-name">&lt;&lt;</span><span class="method-args">( key_file )</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="UserKeyManager.html#M000147">add</a>
</p>
        </div>
      </div>

      <div id="method-M000147" class="method-detail">
        <a name="M000147"></a>

        <div class="method-heading">
          <a href="#M000147" class="method-signature">
          <span class="method-name">add</span><span class="method-args">( key_file )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Add the given key_file to the list of key files that will be used.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000147-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000147-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 92</span>
92:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add</span>( <span class="ruby-identifier">key_file</span> )
93:           <span class="ruby-ivar">@key_files</span>.<span class="ruby-identifier">push</span>( <span class="ruby-identifier">key_file</span> ).<span class="ruby-identifier">uniq!</span>
94:           <span class="ruby-keyword kw">self</span>
95:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000149" class="method-detail">
        <a name="M000149"></a>

        <div class="method-heading">
          <a href="#M000149" class="method-signature">
          <span class="method-name">add_host_key</span><span class="method-args">( key_file )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Add the given key_file to the list of host key files that will be used.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000149-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000149-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 101</span>
101:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_host_key</span>( <span class="ruby-identifier">key_file</span> )
102:           <span class="ruby-ivar">@host_key_files</span>.<span class="ruby-identifier">push</span>( <span class="ruby-identifier">key_file</span> ).<span class="ruby-identifier">uniq!</span>
103:           <span class="ruby-keyword kw">self</span>
104:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000145" class="method-detail">
        <a name="M000145"></a>

        <div class="method-heading">
          <a href="#M000145" class="method-signature">
          <span class="method-name">clear!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clear all knowledge of any loaded user keys. This also clears the list of
default identity files that are to be loaded, thus making it appropriate to
use if a client wishes to NOT use the default identity files.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000145-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000145-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 75</span>
75:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear!</span>
76:           <span class="ruby-ivar">@key_files</span> = []
77:           <span class="ruby-ivar">@known_identities</span> = <span class="ruby-keyword kw">nil</span>
78:           <span class="ruby-keyword kw">self</span>
79:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000146" class="method-detail">
        <a name="M000146"></a>

        <div class="method-heading">
          <a href="#M000146" class="method-signature">
          <span class="method-name">clear_host!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clear all knowledge of any loaded host keys. This also clears the list of
default identity files that are to be loaded, thus making it appropriate to
use if a client wishes to NOT use the default identity files.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000146-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000146-source">
<pre>
    <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 85</span>
85:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_host!</span>
86:           <span class="ruby-ivar">@host_key_files</span> = []
87:           <span class="ruby-ivar">@known_host_identities</span> = <span class="ruby-keyword kw">nil</span>
88:           <span class="ruby-keyword kw">self</span>
89:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000150" class="method-detail">
        <a name="M000150"></a>

        <div class="method-heading">
          <a href="#M000150" class="method-signature">
          <span class="method-name">finish</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
This is used as a hint to the <a
href="UserKeyManager.html">UserKeyManager</a> indicating that the agent
connection is no longer needed. Any other open resources may be closed at
this time.
</p>
<p>
Calling this does NOT indicate that the <a
href="UserKeyManager.html">UserKeyManager</a> will no longer be used.
Identities may still be requested and operations done on loaded identities,
in which case, the agent will be automatically reconnected. This method
simply allows the client connection to be closed when it will not be used
in the immediate future.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000150-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000150-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 115</span>
115:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">finish</span>
116:           <span class="ruby-identifier">close_agent</span>
117:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000152" class="method-detail">
        <a name="M000152"></a>

        <div class="method-heading">
          <a href="#M000152" class="method-signature">
          <span class="method-name">host_identities</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of host identities (public keys) known to this manager.
Host identities are those that identify the current host, and are used
(typically) for hostbased authentication.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000152-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000152-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 154</span>
154:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">host_identities</span>
155:           <span class="ruby-identifier">identities</span> = []
156:           <span class="ruby-ivar">@known_host_identities</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
157: 
158:           <span class="ruby-ivar">@host_key_files</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
159:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@key_existence_tester</span>.<span class="ruby-identifier">readable?</span>( <span class="ruby-identifier">file</span> )
160:               <span class="ruby-keyword kw">begin</span>
161:                 <span class="ruby-identifier">key</span> = <span class="ruby-ivar">@keys</span>.<span class="ruby-identifier">load_public_key</span>( <span class="ruby-identifier">file</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;.pub&quot;</span> )
162:                 <span class="ruby-identifier">identities</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">key</span>
163:                 <span class="ruby-ivar">@known_host_identities</span>[ <span class="ruby-identifier">key</span> ] =
164:                   { <span class="ruby-identifier">:from</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:file</span>, <span class="ruby-identifier">:file</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">file</span> }
165:               <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
166:                 <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">warn</span> <span class="ruby-value str">&quot;could not load public host key file &quot;</span> <span class="ruby-operator">+</span>
167:                   <span class="ruby-node">&quot;'#{file}.pub' (#{e.message} [#{e.class}])&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">warn?</span>
168:               <span class="ruby-keyword kw">end</span>
169:             <span class="ruby-keyword kw">end</span>
170:           <span class="ruby-keyword kw">end</span>
171: 
172:           <span class="ruby-identifier">identities</span>
173:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000151" class="method-detail">
        <a name="M000151"></a>

        <div class="method-heading">
          <a href="#M000151" class="method-signature">
          <span class="method-name">identities</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of identities (public keys) known to this manager. The
origin of the identities may be from files on disk or from an ssh-agent.
Note that identities from an ssh-agent are always listed first in the
array, with other identities coming after.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000151-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000151-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 123</span>
123:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">identities</span>
124:           <span class="ruby-identifier">identities</span> = []
125:           <span class="ruby-ivar">@known_identities</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
126: 
127:           <span class="ruby-identifier">ensure_agent</span>
128:           <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@agent</span>
129:             <span class="ruby-ivar">@agent</span>.<span class="ruby-identifier">identities</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
130:               <span class="ruby-identifier">identities</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">key</span>
131:               <span class="ruby-ivar">@known_identities</span>[ <span class="ruby-identifier">key</span> ] = { <span class="ruby-identifier">:from</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:agent</span> }
132:             <span class="ruby-keyword kw">end</span>
133:           <span class="ruby-keyword kw">end</span>
134: 
135:           <span class="ruby-ivar">@key_files</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
136:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@key_existence_tester</span>.<span class="ruby-identifier">readable?</span>( <span class="ruby-identifier">file</span> )
137:               <span class="ruby-keyword kw">begin</span>
138:                 <span class="ruby-identifier">key</span> = <span class="ruby-ivar">@keys</span>.<span class="ruby-identifier">load_public_key</span>( <span class="ruby-identifier">file</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;.pub&quot;</span> )
139:                 <span class="ruby-identifier">identities</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">key</span>
140:                 <span class="ruby-ivar">@known_identities</span>[ <span class="ruby-identifier">key</span> ] = { <span class="ruby-identifier">:from</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:file</span>, <span class="ruby-identifier">:file</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">file</span> }
141:               <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
142:                 <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">warn</span> <span class="ruby-value str">&quot;could not load public key file &quot;</span> <span class="ruby-operator">+</span>
143:                   <span class="ruby-node">&quot;'#{file}.pub' (#{e.message} [#{e.class}])&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@log</span>.<span class="ruby-identifier">warn?</span>
144:               <span class="ruby-keyword kw">end</span>
145:             <span class="ruby-keyword kw">end</span>
146:           <span class="ruby-keyword kw">end</span>
147: 
148:           <span class="ruby-identifier">identities</span>
149:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000153" class="method-detail">
        <a name="M000153"></a>

        <div class="method-heading">
          <a href="#M000153" class="method-signature">
          <span class="method-name">sign</span><span class="method-args">( identity, data )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sign the given data, using the corresponding private key of the given
identity. If the identity was originally obtained from an ssh-agent, then
the ssh-agent will be used to sign the data, otherwise the private key for
the identity will be loaded from disk (if it hasn&#8217;t been loaded
already) and will then be used to sign the data.
</p>
<p>
Regardless of the identity&#8217;s origin or who does the signing, this
will always return the signature in an SSH2-specified &quot;signature
blob&quot; format.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000153-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000153-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 184</span>
184:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sign</span>( <span class="ruby-identifier">identity</span>, <span class="ruby-identifier">data</span> )
185:           <span class="ruby-identifier">info</span> = <span class="ruby-identifier">find_identity</span>( <span class="ruby-identifier">identity</span> )
186: 
187:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">info</span>[<span class="ruby-identifier">:key</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">info</span>[<span class="ruby-identifier">:from</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:file</span>
188:             <span class="ruby-keyword kw">begin</span>
189:               <span class="ruby-identifier">info</span>[<span class="ruby-identifier">:key</span>] = <span class="ruby-ivar">@keys</span>.<span class="ruby-identifier">load_private_key</span>( <span class="ruby-identifier">info</span>[<span class="ruby-identifier">:file</span>] )
190:             <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span> 
191:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">UserKeyManagerError</span>,
192:                     <span class="ruby-value str">&quot;the given identity is known, &quot;</span> <span class="ruby-operator">+</span>
193:                     <span class="ruby-value str">&quot;but the private key could not be loaded &quot;</span> <span class="ruby-operator">+</span>
194:                     <span class="ruby-node">&quot;(#{e.message} [#{e.class}])&quot;</span>
195:             <span class="ruby-keyword kw">end</span>
196:           <span class="ruby-keyword kw">end</span>
197: 
198:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">info</span>[<span class="ruby-identifier">:key</span>]
199:             <span class="ruby-identifier">sig_blob</span> = <span class="ruby-ivar">@buffers</span>.<span class="ruby-identifier">writer</span>
200:             <span class="ruby-identifier">sig_blob</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-identifier">identity</span>.<span class="ruby-identifier">ssh_type</span>
201:             <span class="ruby-identifier">sig_blob</span>.<span class="ruby-identifier">write_string</span> <span class="ruby-identifier">info</span>[<span class="ruby-identifier">:key</span>].<span class="ruby-identifier">ssh_do_sign</span>( <span class="ruby-identifier">data</span>.<span class="ruby-identifier">to_s</span> )
202:             <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">sig_blob</span>.<span class="ruby-identifier">to_s</span>
203:           <span class="ruby-keyword kw">end</span>
204: 
205:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">info</span>[<span class="ruby-identifier">:from</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:agent</span>
206:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">UserKeyManagerError</span>,
207:               <span class="ruby-value str">&quot;the agent is no longer available&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@agent</span>
208:             <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@agent</span>.<span class="ruby-identifier">sign</span>( <span class="ruby-identifier">identity</span>, <span class="ruby-identifier">data</span>.<span class="ruby-identifier">to_s</span> )
209:           <span class="ruby-keyword kw">end</span>
210: 
211:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">UserKeyManagerError</span>,
212:             <span class="ruby-node">&quot;[BUG] can't determine identity origin (#{info.inspect})&quot;</span>
213:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000155" class="method-detail">
        <a name="M000155"></a>

        <div class="method-heading">
          <a href="#M000155" class="method-signature">
          <span class="method-name">use_agent=</span><span class="method-args">( use_agent )</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Toggles whether the ssh-agent will be used or not. If true, an attempt will
be made to use the ssh-agent. If false, any existing connection to an agent
is closed and the agent will not be used.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000155-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000155-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 223</span>
223:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use_agent=</span>( <span class="ruby-identifier">use_agent</span> )
224:           <span class="ruby-identifier">close_agent</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">use_agent</span>
225:           <span class="ruby-ivar">@use_agent</span> = <span class="ruby-identifier">use_agent</span>
226:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000154" class="method-detail">
        <a name="M000154"></a>

        <div class="method-heading">
          <a href="#M000154" class="method-signature">
          <span class="method-name">use_agent?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Identifies whether the ssh-agent will be used or not.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000154-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000154-source">
<pre>
     <span class="ruby-comment cmt"># File lib/net/ssh/userauth/userkeys.rb, line 216</span>
216:         <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use_agent?</span>
217:           <span class="ruby-ivar">@use_agent</span>
218:         <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>