From c9c20f733e8ac9b7cf6b90f2a397fa13ebb3a2b1 Mon Sep 17 00:00:00 2001 From: Kara <49822414+karashiiro@users.noreply.github.com> Date: Fri, 26 Jul 2024 00:43:00 -0700 Subject: [PATCH] Fix ID related things (#1350) * Fix ID fields to be null when null * Don't hash listing or retainer IDs --- src/Universalis.Application/Util.cs | 23 ++++++------------- .../Views/V1/ListingView.cs | 4 ++-- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/Universalis.Application/Util.cs b/src/Universalis.Application/Util.cs index a3e20ae5..0ab3127a 100644 --- a/src/Universalis.Application/Util.cs +++ b/src/Universalis.Application/Util.cs @@ -53,6 +53,8 @@ public static ListingView ListingToView(Listing l) var ppu = l.PricePerUnit; var listingView = new ListingView { + ListingIdHash = l.ListingId, + RetainerIdHash = l.RetainerId, Hq = l.Hq, OnMannequin = l.OnMannequin, Materia = l.Materia? @@ -67,27 +69,14 @@ public static ListingView ListingToView(Listing l) Total = ppu * l.Quantity, DyeId = l.DyeId, CreatorName = l.CreatorName ?? "", + CreatorIdHash = null, IsCrafted = !string.IsNullOrEmpty(l.CreatorId), + SellerIdHash = null, LastReviewTimeUnixSeconds = new DateTimeOffset(l.LastReviewTime).ToUnixTimeSeconds(), RetainerName = l.RetainerName, RetainerCityId = l.RetainerCityId, }; - using var sha256 = SHA256.Create(); - - if (!string.IsNullOrEmpty(l.CreatorId)) - { - listingView.CreatorIdHash = Hash(sha256, l.CreatorId); - } - - if (!string.IsNullOrEmpty(l.ListingId)) - { - listingView.ListingIdHash = Hash(sha256, l.ListingId); - } - - listingView.SellerIdHash = Hash(sha256, l.SellerId); - listingView.RetainerIdHash = Hash(sha256, l.RetainerId); - return listingView; } @@ -99,8 +88,10 @@ public static ListingView ListingToView(Listing l) /// A hash representing the input string. public static string Hash(HashAlgorithm hasher, string input) { + if (input is null) + return null; Span hash = stackalloc byte[hasher.HashSize / 8]; - ReadOnlySpan bytes = Encoding.UTF8.GetBytes(input ?? ""); + ReadOnlySpan bytes = Encoding.UTF8.GetBytes(input); if (hasher.TryComputeHash(bytes, hash, out _)) // Since we stackalloc the hash buffer, written is not needed return Convert.ToHexString(hash).ToLowerInvariant(); // https://github.com/dotnet/runtime/issues/60393 throw new InvalidOperationException("Destination buffer was too small, this should never occur"); diff --git a/src/Universalis.Application/Views/V1/ListingView.cs b/src/Universalis.Application/Views/V1/ListingView.cs index 8e94c8f3..6c637814 100644 --- a/src/Universalis.Application/Views/V1/ListingView.cs +++ b/src/Universalis.Application/Views/V1/ListingView.cs @@ -85,7 +85,7 @@ public class ListingView : PartiallySerializable, IPriceable, ICopyable public bool IsCrafted { get; init; } /// - /// A SHA256 hash of the ID of this listing. Due to some current client-side bugs, this will almost always be null. + /// The ID of this listing. /// [BsonElement("listingID")] [JsonPropertyName("listingID")] @@ -122,7 +122,7 @@ public class ListingView : PartiallySerializable, IPriceable, ICopyable public int RetainerCityId { get; init; } /// - /// A SHA256 hash of the retainer's ID. + /// The retainer's ID. /// [BsonElement("retainerID")] [JsonPropertyName("retainerID")]