diff --git a/VoidCat/Model/VoidFileMeta.cs b/VoidCat/Model/VoidFileMeta.cs
index 74fc2f9..d6ae701 100644
--- a/VoidCat/Model/VoidFileMeta.cs
+++ b/VoidCat/Model/VoidFileMeta.cs
@@ -59,7 +59,7 @@ public record VoidFileMeta : IVoidFileMeta
///
/// SHA-256 hash of the file
///
- public string? Digest { get; init; }
+ public string? Digest { get; set; }
///
/// Url to download the file
diff --git a/VoidCat/Services/Files/S3FileStore.cs b/VoidCat/Services/Files/S3FileStore.cs
index 29c0bce..032a492 100644
--- a/VoidCat/Services/Files/S3FileStore.cs
+++ b/VoidCat/Services/Files/S3FileStore.cs
@@ -43,8 +43,8 @@ public class S3FileStore : StreamFileStore, IFileStore
}
};
- var r = await _client.PutObjectAsync(req, cts);
- return await HandleCompletedUpload(payload, r.ChecksumSHA256, payload.Meta.Size);
+ await _client.PutObjectAsync(req, cts);
+ return HandleCompletedUpload(payload, payload.Meta.Size);
}
public async ValueTask Egress(EgressRequest request, Stream outStream, CancellationToken cts)
diff --git a/VoidCat/Services/Files/StreamFileStore.cs b/VoidCat/Services/Files/StreamFileStore.cs
index e20590e..3274457 100644
--- a/VoidCat/Services/Files/StreamFileStore.cs
+++ b/VoidCat/Services/Files/StreamFileStore.cs
@@ -1,5 +1,4 @@
using System.Buffers;
-using System.Security.Cryptography;
using VoidCat.Model;
using VoidCat.Model.Exceptions;
using VoidCat.Services.Abstractions;
@@ -45,16 +44,11 @@ public abstract class StreamFileStore
}
}
- var (total, hash) = await IngressInternal(id, payload.InStream, outStream, cts);
- if (payload.Hash != null && !hash.Equals(payload.Hash, StringComparison.InvariantCultureIgnoreCase))
- {
- throw new CryptographicException("Invalid file hash");
- }
-
- return await HandleCompletedUpload(payload, hash, total);
+ var total = await IngressInternal(id, payload.InStream, outStream, cts);
+ return HandleCompletedUpload(payload, total);
}
- protected async Task HandleCompletedUpload(IngressPayload payload, string hash, ulong totalSize)
+ protected PrivateVoidFile HandleCompletedUpload(IngressPayload payload, ulong totalSize)
{
var meta = payload.Meta;
if (payload.IsAppend)
@@ -68,7 +62,6 @@ public abstract class StreamFileStore
{
meta = meta! with
{
- Digest = hash,
Uploaded = DateTimeOffset.UtcNow,
EditSecret = Guid.NewGuid(),
Size = totalSize
@@ -84,13 +77,12 @@ public abstract class StreamFileStore
return vf;
}
- private async Task<(ulong, string)> IngressInternal(Guid id, Stream ingress, Stream outStream,
+ private async Task IngressInternal(Guid id, Stream ingress, Stream outStream,
CancellationToken cts)
{
using var buffer = MemoryPool.Shared.Rent(BufferSize);
var total = 0UL;
- int readLength = 0, offset = 0;
- var sha = SHA256.Create();
+ int readLength, offset = 0;
while ((readLength = await ingress.ReadAsync(buffer.Memory[offset..], cts)) > 0 || offset != 0)
{
if (readLength != 0 && offset + readLength < buffer.Memory.Length)
@@ -104,13 +96,11 @@ public abstract class StreamFileStore
var buf = buffer.Memory[..totalRead];
await outStream.WriteAsync(buf, cts);
await _stats.TrackIngress(id, (ulong) buf.Length);
- sha.TransformBlock(buf.ToArray(), 0, buf.Length, null, 0);
total += (ulong) buf.Length;
offset = 0;
}
- sha.TransformFinalBlock(Array.Empty(), 0, 0);
- return (total, sha.Hash!.ToHex());
+ return total;
}
protected async Task EgressFull(Guid id, Stream inStream, Stream outStream,
diff --git a/VoidCat/Services/Migrations/Database/00-Init.cs b/VoidCat/Services/Migrations/Database/00-Init.cs
index d05f6ce..a4fb587 100644
--- a/VoidCat/Services/Migrations/Database/00-Init.cs
+++ b/VoidCat/Services/Migrations/Database/00-Init.cs
@@ -21,12 +21,12 @@ public class Init : Migration
Create.Table("Files")
.WithColumn("Id").AsGuid().PrimaryKey()
- .WithColumn("Name").AsString()
+ .WithColumn("Name").AsString().Nullable()
.WithColumn("Size").AsInt64()
.WithColumn("Uploaded").AsDateTimeOffset().Indexed().WithDefault(SystemMethods.CurrentUTCDateTime)
.WithColumn("Description").AsString().Nullable()
.WithColumn("MimeType").AsString().WithDefaultValue("application/octet-stream")
- .WithColumn("Digest").AsString()
+ .WithColumn("Digest").AsString().Nullable()
.WithColumn("EditSecret").AsGuid();
Create.Table("UserFiles")
diff --git a/VoidCat/Services/Migrations/MigrateToPostgres.cs b/VoidCat/Services/Migrations/MigrateToPostgres.cs
index 95d0ead..d67e04f 100644
--- a/VoidCat/Services/Migrations/MigrateToPostgres.cs
+++ b/VoidCat/Services/Migrations/MigrateToPostgres.cs
@@ -157,8 +157,6 @@ public class MigrateToPostgres : IMigration
private record UploaderSecretVoidFileMeta : SecretVoidFileMeta
{
- public new string? Digest { get; set; }
-
[JsonConverter(typeof(Base58GuidConverter))]
public Guid? Uploader { get; set; }
}