# File lib/mixlib/authentication/signedheaderauth.rb, line 304
      def do_sign_ssh_agent(rsa_key, string_to_sign)
        # First try loading net-ssh as it is an optional dependency.
        begin
          require "net/ssh"
        rescue LoadError => e
          # ???: Since agent mode is explicitly enabled, should we even catch
          # this in the first place? Might be cleaner to let the LoadError bubble.
          raise AuthenticationError, "net-ssh gem is not available, unable to use ssh-agent signing: #{e.message}"
        end

        # Try to connect to ssh-agent.
        begin
          agent = Net::SSH::Authentication::Agent.connect
        rescue Net::SSH::Authentication::AgentNotAvailable => e
          raise AuthenticationError, "Could not connect to ssh-agent. Make sure the SSH_AUTH_SOCK environment variable is set and ssh-agent is running: #{e.message}"
        end

        begin
          ssh2_signature = agent.sign(rsa_key.public_key, string_to_sign, Net::SSH::Authentication::Agent::SSH_AGENT_RSA_SHA2_256)
        rescue Net::SSH::Authentication::AgentError => e
          raise AuthenticationError, "Unable to sign request with ssh-agent. Make sure your key is loaded with ssh-add: #{e.class.name} #{e.message})"
        end

        # extract signature from SSH Agent response => skip first 20 bytes for RSA keys
        # "\x00\x00\x00\frsa-sha2-256\x00\x00\x01\x00"
        # (see http://api.libssh.org/rfc/PROTOCOL.agent for details)
        ssh2_signature[20..-1]
      end