Make `CRC32.Calculate` return a uint

This commit is contained in:
YoshiRulz 2021-10-04 09:55:12 +10:00
parent 484a1d8fa4
commit f95e03bff3
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 7 additions and 5 deletions

View File

@ -32,7 +32,7 @@ namespace BizHawk.Common
} }
} }
public static int Calculate(ReadOnlySpan<byte> data) public static uint Calculate(ReadOnlySpan<byte> data)
{ {
uint result = 0xFFFFFFFF; uint result = 0xFFFFFFFF;
foreach (var b in data) foreach (var b in data)
@ -40,7 +40,7 @@ namespace BizHawk.Common
result = (result >> 8) ^ Crc32Table[b ^ (result & 0xFF)]; result = (result >> 8) ^ Crc32Table[b ^ (result & 0xFF)];
} }
return (int)~result; return ~result;
} }
} }
} }

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common;
using ISOParser; using ISOParser;
//disc type identification logic //disc type identification logic
@ -301,7 +303,7 @@ namespace BizHawk.Emulation.DiscSystem
return false; return false;
byte[] sector20 = ReadDataSectorCached(20); byte[] sector20 = ReadDataSectorCached(20);
uint zecrc = (uint)BizHawk.Common.CRC32.Calculate(sector20); var zecrc = CRC32.Calculate(sector20);
//known_crcs //known_crcs
if (zecrc == 0xd7b47c06) return true; // AV Tanjou if (zecrc == 0xd7b47c06) return true; // AV Tanjou

View File

@ -565,7 +565,7 @@ namespace BizHawk.Tests.Client.Common.Movie
throw new Exception("Length field corrupted"); throw new Exception("Length field corrupted");
var bytes = buff.AsSpan(0, length - 8); var bytes = buff.AsSpan(0, length - 8);
br.Read(bytes); br.Read(bytes);
if (br.ReadInt32() != CRC32.Calculate(bytes)) if (br.ReadUInt32() != CRC32.Calculate(bytes))
throw new Exception("Data or CRC field corrupted"); throw new Exception("Data or CRC field corrupted");
} }
} }

View File

@ -31,7 +31,7 @@ namespace BizHawk.Tests.Common.checksums
} }
var data = InitialiseArray(); var data = InitialiseArray();
Assert.AreEqual(EXPECTED, (uint) CRC32.Calculate(data)); Assert.AreEqual(EXPECTED, CRC32.Calculate(data));
data = InitialiseArray(); data = InitialiseArray();
DiscHasher.SpecialCRC32 crc32 = new(); DiscHasher.SpecialCRC32 crc32 = new();