Tamir.SharpSsh.jsch.Session.receive_kexinit C# (CSharp) Method

receive_kexinit() private method

private receive_kexinit ( Buffer buf ) : KeyExchange
buf Buffer
return KeyExchange
		private KeyExchange receive_kexinit(Buffer buf)  
		{
			int j=buf.ReadInt();
			if(j!=buf.Length)
			{    // packet was compressed and
				buf.ReadByte();           // j is the size of deflated packet.
				I_S=new byte[buf.index-5];
			}
			else
			{
				I_S=new byte[j-1-buf.ReadByte()];
			}
			System.Array.Copy(buf.buffer, buf.s, I_S, 0, I_S.Length);
			/*
			try{
			byte[] tmp=new byte[I_S.Length];
			Tamir.SharpSsh.java.System.arraycopy(I_S, 0, tmp, 0, I_S.Length);
			Buffer tmpb=new Buffer(tmp);
			System.Console.WriteLine("I_S: len="+I_S.Length);
			tmpb.setOffSet(17);
			System.Console.WriteLine("kex: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("server_host_key: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("cipher.c2s: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("cipher.s2c: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("mac.c2s: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("mac.s2c: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("compression.c2s: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("compression.s2c: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("lang.c2s: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("lang.s2c: "+Encoding.UTF8.GetString(tmpb.getString()));
			System.Console.WriteLine("?: "+(tmpb.getByte()&0xff));
			System.Console.WriteLine("??: "+tmpb.getInt());
			}
			catch(Exception e){
			System.Console.WriteLine(e);
			}
			*/

			send_kexinit();
			String[] guess=KeyExchange.guess(I_S, I_C);
			if(guess==null)
			{
				throw new JSchException("Algorithm negotiation fail");
			}

			if(!isAuthed &&
				(guess[KeyExchange.PROPOSAL_ENC_ALGS_CTOS] == ("none") ||
				(guess[KeyExchange.PROPOSAL_ENC_ALGS_STOC] == ("none"))))
			{
				throw new JSchException("NONE Cipher should not be chosen before authentification is successed.");
			}

			KeyExchange kex=null;
			try
			{
				kex = (KeyExchange)System.Activator.CreateInstance(System.Type.GetType(getConfig(guess[KeyExchange.PROPOSAL_KEX_ALGS])));
			}
			catch(Exception e){ System.Console.Error.WriteLine("kex: "+e); }
			kex._guess=guess;
			kex.init(this, V_S, V_C, I_S, I_C);
			return kex;
		}