Skip to content

Commit a357fcd

Browse files
committed
[2.x] Replace md5 with xxhash
inertiajs/inertia-laravel#653
1 parent 81aa149 commit a357fcd

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

InertiaCore/Extensions/InertiaExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Http.Extensions;
55
using Microsoft.AspNetCore.Mvc;
66
using System.Text;
7+
using System.IO.Hashing;
78

89
namespace InertiaCore.Extensions;
910

@@ -51,11 +52,10 @@ internal static bool Override<TKey, TValue>(this IDictionary<TKey, TValue> dicti
5152
return result?.GetValue(task);
5253
}
5354

54-
internal static string MD5(this string s)
55+
internal static string XXH128(this string s)
5556
{
56-
using var md5 = System.Security.Cryptography.MD5.Create();
5757
var inputBytes = Encoding.UTF8.GetBytes(s);
58-
var hashBytes = md5.ComputeHash(inputBytes);
58+
var hashBytes = XxHash128.Hash(inputBytes);
5959

6060
var sb = new StringBuilder();
6161
foreach (var t in hashBytes)

InertiaCore/InertiaCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
<ItemGroup>
2424
<PackageReference Include="System.IO.Abstractions" Version="19.2.16" />
25+
<PackageReference Include="System.IO.Hashing" Version="8.0.0" />
2526
<PackageReference Include="TypeMerger" Version="2.1.1" />
2627
</ItemGroup>
2728

InertiaCore/Utils/Vite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,5 @@ public static class Vite
247247
/// <summary>
248248
/// Generate the Manifest hash.
249249
/// </summary>
250-
public static string? GetManifestHash() => _instance.GetManifest()?.MD5();
250+
public static string? GetManifestHash() => _instance.GetManifest()?.XXH128();
251251
}

InertiaCoreTests/UnitTestVite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public async Task TestViteVersion()
249249
Assert.That(result, Is.InstanceOf<JsonResult>());
250250

251251
var json = (result as JsonResult)?.Value;
252-
Assert.That((json as Page)?.Version, Is.EqualTo("bba1afd1066309f4a69430e0c446ba8d"));
252+
Assert.That((json as Page)?.Version, Is.EqualTo("24a5fa185351b781e5eb6f813c433180"));
253253
});
254254
}
255255
}

0 commit comments

Comments
 (0)