- new projects WebDrop.FileApi (file service), WebDrop.FileProtocol (shared tickets and receipts) and WebDrop.Sync (WebDAV) - file content of any size goes to the file service; chat, avatars and space structure stay on the main backend - tickets issued by the main backend, receipts by the file service, deletion queue and daily reconciliation - daily database snapshot and file sync to external storage (OpenList/WebDAV) with a 30 day retention - reorganize Core, Storage and Api into feature folders (namespaces unchanged) - web client uploads file frames to the file service and reads them with tickets
20 lines
630 B
C#
20 lines
630 B
C#
using System.Security.Cryptography;
|
|
|
|
namespace WebDrop.Core;
|
|
|
|
/// <summary>服务端只保存令牌的 SHA-256,验证时常量时间比较。</summary>
|
|
public static class TokenHash
|
|
{
|
|
public const int Size = 32;
|
|
|
|
public static byte[] Compute(ReadOnlySpan<byte> token) => SHA256.HashData(token);
|
|
|
|
public static bool Matches(ReadOnlySpan<byte> token, byte[]? expectedHash)
|
|
{
|
|
if (expectedHash is not { Length: Size }) return false;
|
|
Span<byte> actual = stackalloc byte[Size];
|
|
SHA256.HashData(token, actual);
|
|
return CryptographicOperations.FixedTimeEquals(actual, expectedHash);
|
|
}
|
|
}
|