public void Read_ResultsAreExpected() { //Arrange var messageBytes = Utils.ParseHexString(GetMessageHexString()); var record = new TlsRecord(); var message = new ServerHello(); var keyShareEntry = new KeyShareEntry(); var supportedVersion = new ProtocolVersion(); //Act var cursor = new MemoryCursor(messageBytes); var result = TlsRecord.TryParse(cursor, RecordType.Handshake, out record); using (record.Payload.SetCursor(cursor)) { result &= ServerHello.TryParse(cursor, out message); using (message.Payload.SetCursor(cursor)) { result &= cursor.TryParseKeyShare(out var keyShareBuffer); using (keyShareBuffer.SetCursor(cursor)) { keyShareEntry = KeyShareEntry.Parse(cursor); } result &= cursor.TryParseSupportedVersion(out var supportedVersionBuffer); using (supportedVersionBuffer.SetCursor(cursor)) { supportedVersion = ProtocolVersion.Parse(cursor); } result &= cursor.IsEnd(); } result &= cursor.IsEnd(); } result &= cursor.IsEnd(); //Assert Assert.True(result); Assert.Equal(RecordType.Handshake, record.Type); Assert.Equal(ProtocolVersion.Tls12, record.ProtocolVersion); Assert.Equal(HandshakeRandom.Parse(GetBytesOfRandom()), message.Random); Assert.Equal(SessionId.Parse(GetBytesOfSessionId()), message.SessionId); Assert.Equal(Cipher.TLS_AES_128_GCM_SHA256, message.Cipher); Assert.Equal(NamedGroup.X25519, keyShareEntry.Group); Assert.True(GetBytesOfPublicKey().AsSpan().SequenceEqual(keyShareEntry.Key.Read(cursor).Span)); Assert.Equal(ProtocolVersion.Tls13, supportedVersion); }