def keys_for(host)
keys = []
return keys unless File.readable?(source)
entries = host.split(/,/)
File.open(source) do |file|
scanner = StringScanner.new("")
file.each_line do |line|
scanner.string = line
scanner.skip(/\s*/)
next if scanner.match?(/$|#/)
hostlist = scanner.scan(/\S+/).split(/,/)
next unless entries.all? { |entry| hostlist.include?(entry) }
scanner.skip(/\s*/)
type = scanner.scan(/\S+/)
next unless %w(ssh-rsa ssh-dss).include?(type)
scanner.skip(/\s*/)
blob = scanner.rest.unpack("m*").first
keys << Net::SSH::Buffer.new(blob).read_key
end
end
keys
end