From 2a9f1bc244e22231186f4890a32ff0522f60b94e Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Mon, 2 Jan 2023 12:25:35 +0100 Subject: [PATCH] Partial Implementation of AuthSession --- Server/AuthorizationServerSession.cs | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Server/AuthorizationServerSession.cs diff --git a/Server/AuthorizationServerSession.cs b/Server/AuthorizationServerSession.cs new file mode 100644 index 0000000..950dbb8 --- /dev/null +++ b/Server/AuthorizationServerSession.cs @@ -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); + } +} \ No newline at end of file