chore: use spans instead
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 28s
Build, Package and Push Images / sbom-scan (push) Successful in 36s
Build, Package and Push Images / sonarqube (push) Successful in 1m19s
Build, Package and Push Images / container-build (push) Successful in 2m0s
Build, Package and Push Images / container-sbom-scan (push) Successful in 35s

This commit is contained in:
Timothy Schenk 2023-11-25 18:19:27 +01:00
parent 43a5c994df
commit 5b8880f392
2 changed files with 5 additions and 6 deletions

View file

@ -71,11 +71,10 @@ public class AuthSession : TcpSession
protected override void OnReceived(byte[] buffer, long offset, long size) protected override void OnReceived(byte[] buffer, long offset, long size)
{ {
_logger.LogDebug("Length: {Size} & offset: {Offset}", size, offset); _logger.LogDebug("Length: {Size} & offset: {Offset}", size, offset);
Span<byte> decryptedBuffer = new byte[size]; Span<byte> decryptedBuffer = stackalloc byte[(int)size];
// xor every value after the first 8 bytes // xor every value after the first 8 bytes
var dataBuffer = Decrypt(new ArraySegment<byte>(buffer, 8, (int)size - 8).ToArray()); var dataBuffer = Decrypt(buffer.AsSpan(8, (int)size - 8));
_logger.LogDebug("Length {Length}", BitConverter.ToUInt16(buffer, 0)); _logger.LogDebug("Length {Length}", BitConverter.ToUInt16(buffer, 0));
var opCode = BitConverter.ToUInt16(buffer.ToArray(), 2); var opCode = BitConverter.ToUInt16(buffer.ToArray(), 2);
@ -99,7 +98,7 @@ public class AuthSession : TcpSession
base.OnReceived(decryptedBuffer.ToArray(), offset, decryptedBuffer.Length); base.OnReceived(decryptedBuffer.ToArray(), offset, decryptedBuffer.Length);
} }
private static byte[] Decrypt(byte[] buffer) private static Span<byte> Decrypt(Span<byte> buffer)
{ {
for (var i = 0; i < buffer.Length; ++i) for (var i = 0; i < buffer.Length; ++i)
{ {

View file

@ -8,10 +8,10 @@ namespace Server.Packets;
[MessageUrn("packets")] [MessageUrn("packets")]
public class RawPacket public class RawPacket
{ {
public RawPacket(OperationCode operationCode, byte[] messageBody, uint aliveTime, byte unknownValue2, public RawPacket(OperationCode operationCode, Span<byte> messageBody, uint aliveTime, byte unknownValue2,
byte unknownValue, Guid sessionId, AuthSession session) byte unknownValue, Guid sessionId, AuthSession session)
{ {
MessageBody = messageBody; MessageBody = messageBody.ToArray();
UnknownValue2 = unknownValue2; UnknownValue2 = unknownValue2;
UnknownValue = unknownValue; UnknownValue = unknownValue;
SessionId = sessionId; SessionId = sessionId;