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