本文整理汇总了C#中IByteBuffer.GetUnsignedShort方法的典型用法代码示例。如果您正苦于以下问题:C# IByteBuffer.GetUnsignedShort方法的具体用法?C# IByteBuffer.GetUnsignedShort怎么用?C# IByteBuffer.GetUnsignedShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IByteBuffer
的用法示例。
在下文中一共展示了IByteBuffer.GetUnsignedShort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEncryptedPacketLength
const int MAX_PLAINTEXT_LENGTH = 16 * 1024; // 2^14
#endregion Fields
#region Methods
/// <summary>
/// Return how much bytes can be read out of the encrypted data. Be aware that this method will not increase
/// the readerIndex of the given <see cref="IByteBuffer"/>.
/// </summary>
/// <param name="buffer">
/// The <see cref="IByteBuffer"/> to read from. Be aware that it must have at least
/// <see cref="SSL_RECORD_HEADER_LENGTH"/> bytes to read,
/// otherwise it will throw an <see cref="ArgumentException"/>.
/// </param>
/// <param name="offset">Offset to record start.</param>
/// <returns>
/// The length of the encrypted packet that is included in the buffer. This will
/// return <c>-1</c> if the given <see cref="IByteBuffer"/> is not encrypted at all.
/// </returns>
public static int GetEncryptedPacketLength(IByteBuffer buffer, int offset)
{
int packetLength = 0;
// SSLv3 or TLS - Check ContentType
switch (buffer.GetByte(offset))
{
case SSL_CONTENT_TYPE_CHANGE_CIPHER_SPEC:
case SSL_CONTENT_TYPE_ALERT:
case SSL_CONTENT_TYPE_HANDSHAKE:
case SSL_CONTENT_TYPE_APPLICATION_DATA:
break;
default:
// SSLv2 or bad data
return -1;
}
// SSLv3 or TLS - Check ProtocolVersion
int majorVersion = buffer.GetByte(offset + 1);
if (majorVersion == 3)
{
// SSLv3 or TLS
packetLength = buffer.GetUnsignedShort(offset + 3) + SSL_RECORD_HEADER_LENGTH;
if (packetLength <= SSL_RECORD_HEADER_LENGTH)
{
// Neither SSLv3 or TLSv1 (i.e. SSLv2 or bad data)
return -1;
}
}
else
{
// Neither SSLv3 or TLSv1 (i.e. SSLv2 or bad data)
return -1;
}
return packetLength;
}