何冠峰 2025-03-31 18:13:07 +08:00
parent 7bf00d4ff6
commit b3ead90832
6 changed files with 29 additions and 10 deletions

View File

@ -69,8 +69,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
string fileHash = HashUtility.BytesCRC32(_webDataRequestOp.Result);
if (fileHash == _packageHash)
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
{
_steps = ESteps.LoadManifest;
}

View File

@ -59,8 +59,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
string fileHash = HashUtility.BytesCRC32(_fileData);
if (fileHash == _packageHash)
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
{
_steps = ESteps.LoadManifest;
}

View File

@ -59,8 +59,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
string fileHash = HashUtility.BytesCRC32(_fileData);
if (fileHash == _packageHash)
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
{
_steps = ESteps.LoadManifest;
}

View File

@ -72,8 +72,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
string fileHash = HashUtility.BytesCRC32(_webDataRequestOp.Result);
if (fileHash == _packageHash)
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
{
_steps = ESteps.LoadManifest;
}

View File

@ -69,8 +69,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData)
{
string fileHash = HashUtility.BytesCRC32(_webDataRequestOp.Result);
if (fileHash == _packageHash)
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
{
_steps = ESteps.LoadManifest;
}

View File

@ -8,6 +8,30 @@ namespace YooAsset
{
internal static class ManifestTools
{
/// <summary>
/// 验证清单文件的二进制数据
/// </summary>
public static bool VerifyManifestData(byte[] fileData, string hashValue)
{
if (fileData == null || fileData.Length == 0)
return false;
if (string.IsNullOrEmpty(hashValue))
return false;
// 注意:兼容俩种验证方式
// 注意计算MD5的哈希值通常为32个字符
string fileHash;
if (hashValue.Length == 32)
fileHash = HashUtility.BytesMD5(fileData);
else
fileHash = HashUtility.BytesCRC32(fileData);
if (fileHash == hashValue)
return true;
else
return false;
}
/// <summary>
/// 序列化JSON文件
/// </summary>