feat: auth, compression, jwt, paste wip, roles, ratelimiting

This commit is contained in:
2025-11-24 21:50:26 -05:00
parent 050f0bc935
commit 6ec1a7fa7b
26 changed files with 611 additions and 473 deletions
+44
View File
@@ -0,0 +1,44 @@
using System.IO.Compression;
namespace SharpbinV3.Services
{
public class CompressionService : ICompressionService
{
public byte[] Compress(byte[] data)
{
byte[] result = new byte[data.Length];
using (MemoryStream ms = new())
{
using (GZipStream gzip = new(ms, CompressionMode.Compress))
{
gzip.Write(data, 0, data.Length);
}
result = ms.ToArray();
}
if (result.Length > 0 && result.Length < data.Length)
return result;
return data;
}
public byte[] Decompress(byte[] compressedData)
{
ArgumentNullException.ThrowIfNull(compressedData);
if (!IsCompressed(compressedData))
throw new ArgumentException("Data is not in a valid compressed format.", nameof(compressedData));
using (MemoryStream ms = new())
{
using MemoryStream compressedStream = new(compressedData);
using GZipStream gzip = new(compressedStream, CompressionMode.Decompress);
gzip.CopyTo(ms);
}
return compressedData;
}
private static bool IsCompressed(byte[] data)
{
return data.Length >= 2 && data[0] == 0x1F && data[1] == 0x8B;
}
}
}