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