<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />

HandshakeMessageOutput

using System; using System.IO; namespace Org.BouncyCastle.Tls { internal sealed class HandshakeMessageOutput : MemoryStream { internal static int GetLength(int bodyLength) { return 4 + bodyLength; } internal static void Send(TlsProtocol protocol, short handshakeType, byte[] body) { HandshakeMessageOutput handshakeMessageOutput = new HandshakeMessageOutput(handshakeType, body.Length); handshakeMessageOutput.Write(body, 0, body.Length); handshakeMessageOutput.Send(protocol); } internal HandshakeMessageOutput(short handshakeType) : this(handshakeType, 60) { } internal HandshakeMessageOutput(short handshakeType, int bodyLength) : base(GetLength(bodyLength)) { TlsUtilities.CheckUint8(handshakeType); TlsUtilities.WriteUint8(handshakeType, this); Seek(3, SeekOrigin.Current); } internal void Send(TlsProtocol protocol) { int i = Convert.ToInt32(Length) - 4; TlsUtilities.CheckUint24(i); Seek(1, SeekOrigin.Begin); TlsUtilities.WriteUint24(i, this); byte[] buffer = GetBuffer(); int len = Convert.ToInt32(Length); protocol.WriteHandshakeMessage(buffer, 0, len); Dispose(); } internal void PrepareClientHello(TlsHandshakeHash handshakeHash, int bindersSize) { int i = Convert.ToInt32(Length) - 4 + bindersSize; TlsUtilities.CheckUint24(i); Seek(1, SeekOrigin.Begin); TlsUtilities.WriteUint24(i, this); byte[] buffer = GetBuffer(); int length = Convert.ToInt32(Length); handshakeHash.Update(buffer, 0, length); Seek(0, SeekOrigin.End); } internal void SendClientHello(TlsClientProtocol clientProtocol, TlsHandshakeHash handshakeHash, int bindersSize) { byte[] buffer = GetBuffer(); int num = Convert.ToInt32(Length); if (bindersSize > 0) handshakeHash.Update(buffer, num - bindersSize, bindersSize); clientProtocol.WriteHandshakeMessage(buffer, 0, num); Dispose(); } } }