using System;
using System.Collections.Generic;
using System.Security.Cryptography;
namespace Renci.SshNet.Messages.Transport
{
    /// 
    /// Represents SSH_MSG_KEXINIT message.
    /// 
    [Message("SSH_MSG_KEXINIT", 20)]
    public class KeyExchangeInitMessage : Message
    {
        private static RNGCryptoServiceProvider _randomizer = new System.Security.Cryptography.RNGCryptoServiceProvider();
        /// 
        /// Initializes a new instance of the  class.
        /// 
        public KeyExchangeInitMessage()
        {
            var cookie = new byte[16];
            _randomizer.GetBytes(cookie);
            this.Cookie = cookie;
        }
        #region Message Properties
        /// 
        /// Gets session cookie.
        /// 
        public byte[] Cookie { get; private set; }
        /// 
        /// Gets or sets supported key exchange algorithms.
        /// 
        /// 
        /// Supported key exchange algorithms.
        /// 
        public string[] KeyExchangeAlgorithms { get; set; }
        /// 
        /// Gets or sets supported server host key algorithms.
        /// 
        /// 
        /// Supported server host key algorithms.
        /// 
        public string[] ServerHostKeyAlgorithms { get; set; }
        /// 
        /// Gets or sets supported encryption algorithms client to server.
        /// 
        /// 
        /// Supported encryption algorithms client to server.
        /// 
        public string[] EncryptionAlgorithmsClientToServer { get; set; }
        /// 
        /// Gets or sets supported encryption algorithms server to client.
        /// 
        /// 
        /// Supported encryption algorithms server to client.
        /// 
        public string[] EncryptionAlgorithmsServerToClient { get; set; }
        /// 
        /// Gets or sets supported hash algorithms client to server.
        /// 
        /// 
        /// Supported hash algorithms client to server.
        /// 
        public string[] MacAlgorithmsClientToServer { get; set; }
        /// 
        /// Gets or sets supported hash algorithms server to client.
        /// 
        /// 
        /// Supported hash algorithms server to client.
        /// 
        public string[] MacAlgorithmsServerToClient { get; set; }
        /// 
        /// Gets or sets supported compression algorithms client to server.
        /// 
        /// 
        /// Supported compression algorithms client to server.
        /// 
        public string[] CompressionAlgorithmsClientToServer { get; set; }
        /// 
        /// Gets or sets supported compression algorithms server to client.
        /// 
        /// 
        /// Supported compression algorithms server to client.
        /// 
        public string[] CompressionAlgorithmsServerToClient { get; set; }
        /// 
        /// Gets or sets supported languages client to server.
        /// 
        /// 
        /// Supported languages client to server.
        /// 
        public string[] LanguagesClientToServer { get; set; }
        /// 
        /// Gets or sets supported languages server to client.
        /// 
        /// 
        /// The languages server to client.
        /// 
        public string[] LanguagesServerToClient { get; set; }
        /// 
        /// Gets or sets a value indicating whether first key exchange packet follows.
        /// 
        /// 
        /// 	true if first key exchange packet follows; otherwise, false.
        /// 
        public bool FirstKexPacketFollows { get; set; }
        /// 
        /// Gets or sets the reserved value.
        /// 
        /// 
        /// The reserved value.
        /// 
        public UInt32 Reserved { get; set; }
        #endregion
        /// 
        /// Called when type specific data need to be loaded.
        /// 
        protected override void LoadData()
        {
            this.ResetReader();
            this.Cookie = this.ReadBytes(16);
            this.KeyExchangeAlgorithms = this.ReadNamesList();
            this.ServerHostKeyAlgorithms = this.ReadNamesList();
            this.EncryptionAlgorithmsClientToServer = this.ReadNamesList();
            this.EncryptionAlgorithmsServerToClient = this.ReadNamesList();
            this.MacAlgorithmsClientToServer = this.ReadNamesList();
            this.MacAlgorithmsServerToClient = this.ReadNamesList();
            this.CompressionAlgorithmsClientToServer = this.ReadNamesList();
            this.CompressionAlgorithmsServerToClient = this.ReadNamesList();
            this.LanguagesClientToServer = this.ReadNamesList();
            this.LanguagesServerToClient = this.ReadNamesList();
            this.FirstKexPacketFollows = this.ReadBoolean();
            this.Reserved = this.ReadUInt32();
        }
        /// 
        /// Called when type specific data need to be saved.
        /// 
        protected override void SaveData()
        {
            this.Write(this.Cookie);
            this.Write(this.KeyExchangeAlgorithms);
            this.Write(this.ServerHostKeyAlgorithms);
            this.Write(this.EncryptionAlgorithmsClientToServer);
            this.Write(this.EncryptionAlgorithmsServerToClient);
            this.Write(this.MacAlgorithmsClientToServer);
            this.Write(this.MacAlgorithmsServerToClient);
            this.Write(this.CompressionAlgorithmsClientToServer);
            this.Write(this.CompressionAlgorithmsServerToClient);
            this.Write(this.LanguagesClientToServer);
            this.Write(this.LanguagesServerToClient);
            this.Write(this.FirstKexPacketFollows);
            this.Write(this.Reserved);
        }
    }
}