namespace Renci.SshNet.Messages.Authentication
{
    /// 
    /// Represents "hostbased" SSH_MSG_USERAUTH_REQUEST message.
    /// 
    internal class RequestMessageHost : RequestMessage
    {
        /// 
        /// Gets the name of the authentication method.
        /// 
        /// 
        /// The name of the method.
        /// 
        public override string MethodName
        {
            get
            {
                return "hostbased";
            }
        }
        /// 
        /// Gets the public key algorithm for host key
        /// 
        public string PublicKeyAlgorithm { get; private set; }
        /// 
        /// Gets or sets the public host key and certificates for client host.
        /// 
        /// 
        /// The public host key.
        /// 
        public byte[] PublicHostKey { get; private set; }
        /// 
        /// Gets or sets the name of the client host.
        /// 
        /// 
        /// The name of the client host.
        /// 
        public string ClientHostName { get; private set; }
        /// 
        /// Gets or sets the client username on the client host
        /// 
        /// 
        /// The client username.
        /// 
        public string ClientUsername { get; private set; }
        /// 
        /// Gets or sets the signature.
        /// 
        /// 
        /// The signature.
        /// 
        public byte[] Signature { get; set; }
        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// Name of the service.
        /// Authentication username.
        /// The public key algorithm.
        /// The public host key.
        /// Name of the client host.
        /// The client username.
        public RequestMessageHost(ServiceName serviceName, string username, string publicKeyAlgorithm, byte[] publicHostKey, string clientHostName, string clientUsername)
            : base(serviceName, username)
        {
            this.PublicKeyAlgorithm = publicKeyAlgorithm;
            this.PublicHostKey = publicHostKey;
            this.ClientHostName = clientHostName;
            this.ClientUsername = clientUsername;
        }
        /// 
        /// Called when type specific data need to be saved.
        /// 
        protected override void SaveData()
        {
            base.SaveData();
            this.WriteAscii(this.PublicKeyAlgorithm);
            this.WriteBinaryString(this.PublicHostKey);
            this.Write(this.ClientHostName);
            this.Write(this.ClientUsername);
            if (this.Signature != null)
                this.WriteBinaryString(this.Signature);
        }
    }
}