Beispiel #1
0
        public void TestUnencrypted()
        {
            using var buffer = new PacketBuffer();

            using (var message = new FakeMessage {
                Text = text, MessageFlags = MessageFlags.Unencrypted
            })
            {
                message.WritePacket(buffer, PacketRole.Client);
            }

            buffer.Position = 0;
            byte[]? content;

            using (var received = new FakeMessage())
            {
                received.ReadPacket(buffer, PacketRole.Server);
                content = received.PacketContent;

                Assert.AreEqual(text, received.Text);
            }

            // Reading a packet must not alter its contents
            Assert.IsNotNull(content);
            using var contentBuffer = new PacketBuffer(content);
            Assert.AreEqual(text, contentBuffer.ReadMediumString());
        }
Beispiel #2
0
        public void TestEncrypted()
        {
            using var message = new FakeMessage { Text = text };
            Span <byte> key = stackalloc byte[64];

            RandomNumberGenerator.Fill(key);

            using var buffer = new PacketBuffer();

            message.Encrypt(key);
            message.WritePacket(buffer, PacketRole.Client);

            buffer.Position = 0;

            using var received = new FakeMessage();
            received.ReadPacket(buffer, PacketRole.Server);
            received.Decrypt(key);

            Assert.AreEqual(text, received.Text);
        }