当前位置: 首页>>代码示例>>C#>>正文


C# Buffer.GetLength方法代码示例

本文整理汇总了C#中Buffer.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Buffer.GetLength方法的具体用法?C# Buffer.GetLength怎么用?C# Buffer.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Buffer的用法示例。


在下文中一共展示了Buffer.GetLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Send_kexinit

		/// <exception cref="System.Exception"></exception>
		private void Send_kexinit()
		{
			if (in_kex)
			{
				return;
			}
			string cipherc2s = GetConfig("cipher.c2s");
			string ciphers2c = GetConfig("cipher.s2c");
			string[] not_available = CheckCiphers(GetConfig("CheckCiphers"));
			if (not_available != null && not_available.Length > 0)
			{
				cipherc2s = Util.DiffString(cipherc2s, not_available);
				ciphers2c = Util.DiffString(ciphers2c, not_available);
				if (cipherc2s == null || ciphers2c == null)
				{
					throw new JSchException("There are not any available ciphers.");
				}
			}
			in_kex = true;
			kex_start_time = Runtime.CurrentTimeMillis();
			// byte      SSH_MSG_KEXINIT(20)
			// byte[16]  cookie (random bytes)
			// string    kex_algorithms
			// string    server_host_key_algorithms
			// string    encryption_algorithms_client_to_server
			// string    encryption_algorithms_server_to_client
			// string    mac_algorithms_client_to_server
			// string    mac_algorithms_server_to_client
			// string    compression_algorithms_client_to_server
			// string    compression_algorithms_server_to_client
			// string    languages_client_to_server
			// string    languages_server_to_client
			Buffer buf = new Buffer();
			// send_kexinit may be invoked
			Packet packet = new Packet(buf);
			// by user thread.
			packet.Reset();
			buf.PutByte(unchecked((byte)SSH_MSG_KEXINIT));
			lock (random)
			{
				random.Fill(buf.buffer, buf.index, 16);
				buf.Skip(16);
			}
			buf.PutString(Util.Str2byte(GetConfig("kex")));
			buf.PutString(Util.Str2byte(GetConfig("server_host_key")));
			buf.PutString(Util.Str2byte(cipherc2s));
			buf.PutString(Util.Str2byte(ciphers2c));
			buf.PutString(Util.Str2byte(GetConfig("mac.c2s")));
			buf.PutString(Util.Str2byte(GetConfig("mac.s2c")));
			buf.PutString(Util.Str2byte(GetConfig("compression.c2s")));
			buf.PutString(Util.Str2byte(GetConfig("compression.s2c")));
			buf.PutString(Util.Str2byte(GetConfig("lang.c2s")));
			buf.PutString(Util.Str2byte(GetConfig("lang.s2c")));
			buf.PutByte(unchecked((byte)0));
			buf.PutInt(0);
			buf.SetOffSet(5);
			I_C = new byte[buf.GetLength()];
			buf.GetByte(I_C);
			Write(packet);
			if (JSch.GetLogger().IsEnabled(Logger.INFO))
			{
				JSch.GetLogger().Log(Logger.INFO, "SSH_MSG_KEXINIT sent");
			}
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:65,代码来源:Session.cs

示例2: ThrowStatusError

		/// <exception cref="NSch.SftpException"></exception>
		private void ThrowStatusError(Buffer buf, int i)
		{
			if (server_version >= 3 && buf.GetLength() >= 4)
			{
				// WindRiver's sftp will send invalid 
				// SSH_FXP_STATUS packet.
				byte[] str = buf.GetString();
				//byte[] tag=buf.getString();
				throw new SftpException(i, Util.Byte2str(str, UTF8));
			}
			else
			{
				throw new SftpException(i, "Failure");
			}
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:16,代码来源:ChannelSftp.cs

示例3: Receive_kexinit

		/// <exception cref="System.Exception"></exception>
		private KeyExchange Receive_kexinit(Buffer buf)
		{
			int j = buf.GetInt();
			if (j != buf.GetLength())
			{
				// packet was compressed and
				buf.GetByte();
				// j is the size of deflated packet.
				I_S = new byte[buf.index - 5];
			}
			else
			{
				I_S = new byte[j - 1 - buf.GetByte()];
			}
			System.Array.Copy(buf.buffer, buf.s, I_S, 0, I_S.Length);
			if (!in_kex)
			{
				// We are in rekeying activated by the remote!
				Send_kexinit();
			}
			guess = KeyExchange.Guess(I_S, I_C);
			if (guess == null)
			{
				throw new JSchException("Algorithm negotiation fail");
			}
			if (!isAuthed && (guess[KeyExchange.PROPOSAL_ENC_ALGS_CTOS].Equals("none") || (guess
				[KeyExchange.PROPOSAL_ENC_ALGS_STOC].Equals("none"))))
			{
				throw new JSchException("NONE Cipher should not be chosen before authentification is successed."
					);
			}
			KeyExchange kex = null;
			try
			{
				Type c = Sharpen.Runtime.GetType(GetConfig(guess[KeyExchange.PROPOSAL_KEX_ALGS]));
				kex = (KeyExchange)(System.Activator.CreateInstance(c));
			}
			catch (Exception e)
			{
				throw new JSchException(e.ToString(), e);
			}
			kex.Init(this, V_S, V_C, I_S, I_C);
			return kex;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:45,代码来源:Session.cs

示例4: Start


//.........这里部分代码省略.........
			{
				try
				{
					token = context.Init(token, 0, token.Length);
				}
				catch (JSchException)
				{
					// TODO
					// ERRTOK should be sent?
					// byte        SSH_MSG_USERAUTH_GSSAPI_ERRTOK
					// string      error token
					return false;
				}
				if (token != null)
				{
					packet.Reset();
					buf.PutByte(unchecked((byte)SSH_MSG_USERAUTH_GSSAPI_TOKEN));
					buf.PutString(token);
					session.Write(packet);
				}
				if (!context.IsEstablished())
				{
					buf = session.Read(buf);
					command = buf.GetCommand() & unchecked((int)(0xff));
					if (command == SSH_MSG_USERAUTH_GSSAPI_ERROR)
					{
						// uint32    major_status
						// uint32    minor_status
						// string    message
						// string    language tag
						buf = session.Read(buf);
						command = buf.GetCommand() & unchecked((int)(0xff));
					}
					else
					{
						//return false;
						if (command == SSH_MSG_USERAUTH_GSSAPI_ERRTOK)
						{
							// string error token
							buf = session.Read(buf);
							command = buf.GetCommand() & unchecked((int)(0xff));
						}
					}
					//return false;
					if (command == SSH_MSG_USERAUTH_FAILURE)
					{
						return false;
					}
					buf.GetInt();
					buf.GetByte();
					buf.GetByte();
					token = buf.GetString();
				}
			}
			Buffer mbuf = new Buffer();
			// string    session identifier
			// byte      SSH_MSG_USERAUTH_REQUEST
			// string    user name
			// string    service
			// string    "gssapi-with-mic"
			mbuf.PutString(session.GetSessionId());
			mbuf.PutByte(unchecked((byte)SSH_MSG_USERAUTH_REQUEST));
			mbuf.PutString(_username);
			mbuf.PutString(Util.Str2byte("ssh-connection"));
			mbuf.PutString(Util.Str2byte("gssapi-with-mic"));
			byte[] mic = context.GetMIC(mbuf.buffer, 0, mbuf.GetLength());
			if (mic == null)
			{
				return false;
			}
			packet.Reset();
			buf.PutByte(unchecked((byte)SSH_MSG_USERAUTH_GSSAPI_MIC));
			buf.PutString(mic);
			session.Write(packet);
			context.Dispose();
			buf = session.Read(buf);
			command = buf.GetCommand() & unchecked((int)(0xff));
			if (command == SSH_MSG_USERAUTH_SUCCESS)
			{
				return true;
			}
			else
			{
				if (command == SSH_MSG_USERAUTH_FAILURE)
				{
					buf.GetInt();
					buf.GetByte();
					buf.GetByte();
					byte[] foo = buf.GetString();
					int partial_success = buf.GetByte();
					//System.err.println(new String(foo)+
					//		 " partial_success:"+(partial_success!=0));
					if (partial_success != 0)
					{
						throw new JSchPartialAuthException(Util.Byte2str(foo));
					}
				}
			}
			return false;
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:101,代码来源:UserAuthGSSAPIWithMIC.cs


注:本文中的Buffer.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。