Methods
Attributes
[R] source
Public Class methods
add(host, key)
    # File lib/net/ssh/known-hosts.rb, line 18
18:       def add(host, key)
19:         hostfile_locations.each do |file|
20:           begin
21:             KnownHosts.new(file).add(host, key)
22:             return
23:           rescue SystemCallError
24:             # try the next hostfile
25:           end
26:         end
27:       end
canonize(location, port)
    # File lib/net/ssh/known-hosts.rb, line 8
 8:       def canonize(location, port)
 9:         value = location
10:         value = "[#{value}]:#{port}" if port && port != 22
11:         value
12:       end
home_directory()
    # File lib/net/ssh/known-hosts.rb, line 42
42:       def home_directory
43:         ENV['HOME'] ||
44:           (ENV['HOMEPATH'] && "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}") ||
45:           "/"
46:       end
hostfile_locations()
    # File lib/net/ssh/known-hosts.rb, line 33
33:       def hostfile_locations
34:         @hostfile_locations ||= [
35:           "#{home_directory}/.ssh/known_hosts",
36:           "#{home_directory}/.ssh/known_hosts2",
37:           "/etc/ssh/ssh_known_hosts",
38:           "/etc/ssh/ssh_known_hosts2"
39:         ]
40:       end
new(source)
    # File lib/net/ssh/known-hosts.rb, line 52
52:     def initialize(source)
53:       @source = source
54:     end
search_for(host)
    # File lib/net/ssh/known-hosts.rb, line 14
14:       def search_for(host)
15:         search_in(hostfile_locations, host)
16:       end
search_in(files, host)
    # File lib/net/ssh/known-hosts.rb, line 29
29:       def search_in(files, host)
30:         files.map { |file| KnownHosts.new(file).keys_for(host) }.flatten
31:       end
Public Instance methods
add(host, key)
    # File lib/net/ssh/known-hosts.rb, line 84
84:     def add(host, key)
85:       dir = File.dirname(source)
86:       Dir.mkdir(dir, 0700) if !File.exists?(dir)
87: 
88:       File.open(source, "a") do |file|
89:         buffer = Net::SSH::Transport::OSSL::Buffer.new
90:         buffer.write_key(key)
91:         blob = [buffer.to_s].pack("m*").gsub(/\s/, "")
92:         file.puts "#{Array(host).join(',')} #{key.ssh_type} #{blob}"
93:       end
94:     end
keys_for(host)
    # File lib/net/ssh/known-hosts.rb, line 56
56:     def keys_for(host)
57:       keys = []
58:       hosts = Array(host)
59: 
60:       File.open(source) do |file|
61:         scanner = StringScanner.new("")
62:         file.each_line do |line|
63:           scanner.string = line
64: 
65:           scanner.skip(/\s*/)
66:           next if scanner.match?(/$|#/)
67: 
68:           hostlist = scanner.scan(/\S+/)
69:           next if (hostlist.split(/,/) & hosts).empty?
70: 
71:           scanner.skip(/\s*/)
72:           type = scanner.scan(/\S+/)
73:           scanner.skip(/\s*/)
74:           blob = scanner.rest.unpack("m*").first
75:           keys << Net::SSH::Transport::OSSL::Buffer.new(blob).read_key
76:         end
77:       end
78: 
79:       keys
80:     rescue SystemCallError
81:       return []
82:     end