136: def sign(identity, data)
137: info = known_identities[identity] or raise KeyManagerError, "the given identity is unknown to the key manager"
138:
139: if info[:key].nil? && info[:from] == :file
140: begin
141: info[:key] = KeyFactory.load_private_key(info[:file], options[:passphrase], true)
142: rescue Exception, OpenSSL::OpenSSLError => e
143: raise KeyManagerError, "the given identity is known, but the private key could not be loaded: #{e.class} (#{e.message})"
144: end
145: end
146:
147: if info[:key]
148: return Net::SSH::Buffer.from(:string, identity.ssh_type,
149: :string, info[:key].ssh_do_sign(data.to_s)).to_s
150: end
151:
152: if info[:from] == :agent
153: raise KeyManagerError, "the agent is no longer available" unless agent
154: return agent.sign(identity, data.to_s)
155: end
156:
157: raise KeyManagerError, "[BUG] can't determine identity origin (#{info.inspect})"
158: end