# File lib/net/ssh/userauth/userkeys.rb, line 184
        def sign( identity, data )
          info = find_identity( identity )

          if info[:key].nil? && info[:from] == :file
            begin
              info[:key] = @keys.load_private_key( info[:file] )
            rescue Exception => e 
              raise UserKeyManagerError,
                    "the given identity is known, " +
                    "but the private key could not be loaded " +
                    "(#{e.message} [#{e.class}])"
            end
          end

          if info[:key]
            sig_blob = @buffers.writer
            sig_blob.write_string identity.ssh_type
            sig_blob.write_string info[:key].ssh_do_sign( data.to_s )
            return sig_blob.to_s
          end

          if info[:from] == :agent
            raise UserKeyManagerError,
              "the agent is no longer available" unless @agent
            return @agent.sign( identity, data.to_s )
          end

          raise UserKeyManagerError,
            "[BUG] can't determine identity origin (#{info.inspect})"
        end