Class DownloadVerifier
- Namespace
- McServerLauncher.Services
- Assembly
- McServerLauncher.dll
Verifies a downloaded file's hash against the checksum an official API (Mojang, Adoptium, Paper) already returns alongside the download URL. On mismatch the file is deleted and an exception is thrown, so a corrupted or tampered download is never silently trusted.
public static class DownloadVerifier
- Inheritance
-
DownloadVerifier
- Inherited Members
Methods
ComputeHashAsync(string, HashAlgorithmName, CancellationToken)
Computes the hex-encoded hash of a file in a streaming fashion (no full read into memory).
public static Task<string> ComputeHashAsync(string filePath, HashAlgorithmName algorithm, CancellationToken ct = default)
Parameters
filePathstringalgorithmHashAlgorithmNamectCancellationToken
Returns
VerifyAsync(string, string?, HashAlgorithmName, CancellationToken)
Verifies filePath against expectedHex using
algorithm (SHA1 or SHA256). A null/empty expected hash means the API
didn't provide one for this asset; verification is skipped rather than failing the download.
public static Task VerifyAsync(string filePath, string? expectedHex, HashAlgorithmName algorithm, CancellationToken ct = default)
Parameters
filePathstringexpectedHexstringalgorithmHashAlgorithmNamectCancellationToken