# grok empty or commented ssh_known_hosts lines, and handle different key types

$OpenBSD: patch-lib_net_ssh_host-key-verifier_rb,v 1.1.1.1 2007/05/31 03:45:52 jcs Exp $
--- lib/net/ssh/host-key-verifier.rb.orig	Wed Dec 31 17:00:00 1969
+++ lib/net/ssh/host-key-verifier.rb	Wed May 30 21:36:49 2007
@@ -10,10 +10,12 @@ module Net
             host = item[:host] || arguments[:peer][:host]
             ip   = item[:ip]   || arguments[:peer][:ip]
             port = item[:port] || arguments[:peer][:port]
+            type = item[:type] || arguments[:peer][:type]
 
             host == arguments[:peer][:host] &&
             ip   == arguments[:peer][:ip]   &&
-            port == arguments[:peer][:port]
+            port == arguments[:peer][:port] &&
+            type == arguments[:key].ssh_type
           end
 
         # we've never seen this host before, so just automatically add the key.
@@ -84,7 +86,10 @@ module Net
         end
 
         def load_keys_from(path)
-          File.readlines(path).map do |line|
+          keys = []
+          File.readlines(path).each do |line|
+            next if line.chomp.empty? || line =~ /^#/
+
             host, type, key = line.chomp.split
             host, address = host.split(/,/)
 
@@ -99,10 +104,11 @@ module Net
 
             key = key.unpack("m*").first
             
-            { :host => host, :ip => address, :port => port, :type => type, :key => key }
+            keys.push({ :host => host, :ip => address, :port => port, :type => type, :key => key })
           end
+          keys
         end
     end
 
   end
-end
\ No newline at end of file
+end
