Partial Implementation of AuthSession

This commit is contained in:
Timothy Schenk 2023-01-02 12:25:35 +01:00
parent e3eb36639a
commit 2a9f1bc244

View file

@ -0,0 +1,44 @@
using System.Net.Sockets;
using Microsoft.Extensions.Logging;
using NetCoreServer;
namespace Server;
public class AuthorizationServerSession : TcpSession
{
private readonly ILogger _logger;
private readonly AesProvider _aesProvider;
public AuthorizationServerSession(AuthorizationServer server, ILogger logger, AesProvider aesProvider) : base(server)
{
_logger = logger;
_aesProvider = aesProvider;
}
public override long Send(byte[] buffer, long offset, long size)
{
var bytes = _aesProvider.Encrypt(buffer);
return bytes.Length;
}
public override long Receive(byte[] buffer, long offset, long size)
{
var bytes = _aesProvider.Decrypt(buffer);
return bytes.Length;
}
protected override void OnConnected()
{
_logger.LogInformation("Session with Id {Id} is connected.", Id);
}
protected override void OnDisconnected()
{
_logger.LogInformation("Session with Id {Id} is disconnected.", Id);
}
protected override void OnError(SocketError error)
{
_logger.LogError("Authorization session caught an error with code {error}", error);
}
}