mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
🐛Move checksum initializers to instance constructors.
This commit is contained in:
@@ -43,14 +43,14 @@ namespace DiscImageChef.Checksums
|
||||
{
|
||||
const ushort CRC16_POLY = 0xA001;
|
||||
const ushort CRC16_SEED = 0x0000;
|
||||
ushort hashInt;
|
||||
|
||||
ushort[] table;
|
||||
readonly ushort[] table;
|
||||
ushort hashInt;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the CRC16 table and seed
|
||||
/// </summary>
|
||||
public void Init()
|
||||
public Crc16Context()
|
||||
{
|
||||
hashInt = CRC16_SEED;
|
||||
|
||||
@@ -58,9 +58,11 @@ namespace DiscImageChef.Checksums
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
ushort entry = (ushort)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ CRC16_POLY);
|
||||
else entry = (ushort)(entry >> 1);
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ CRC16_POLY);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
|
||||
table[i] = entry;
|
||||
}
|
||||
@@ -102,7 +104,7 @@ namespace DiscImageChef.Checksums
|
||||
StringBuilder crc16Output = new StringBuilder();
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ CRC16_SEED).Length; i++)
|
||||
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt ^ CRC16_SEED).Length; i++)
|
||||
crc16Output.Append(BigEndianBitConverter.GetBytes(hashInt ^ CRC16_SEED)[i].ToString("x2"));
|
||||
|
||||
return crc16Output.ToString();
|
||||
@@ -126,7 +128,7 @@ namespace DiscImageChef.Checksums
|
||||
public static string File(string filename, out byte[] hash)
|
||||
{
|
||||
FileStream fileStream = new FileStream(filename, FileMode.Open);
|
||||
ushort localhashInt;
|
||||
ushort localhashInt;
|
||||
|
||||
localhashInt = CRC16_SEED;
|
||||
|
||||
@@ -134,9 +136,11 @@ namespace DiscImageChef.Checksums
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
ushort entry = (ushort)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ CRC16_POLY);
|
||||
else entry = (ushort)(entry >> 1);
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ CRC16_POLY);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
|
||||
localTable[i] = entry;
|
||||
}
|
||||
@@ -146,7 +150,7 @@ namespace DiscImageChef.Checksums
|
||||
(ushort)((localhashInt >> 8) ^ localTable[fileStream.ReadByte() ^ (localhashInt & 0xff)]);
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
hash = BigEndianBitConverter.GetBytes(localhashInt);
|
||||
hash = BigEndianBitConverter.GetBytes(localhashInt);
|
||||
|
||||
StringBuilder crc16Output = new StringBuilder();
|
||||
|
||||
@@ -186,9 +190,11 @@ namespace DiscImageChef.Checksums
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
ushort entry = (ushort)i;
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1) entry = (ushort)((entry >> 1) ^ polynomial);
|
||||
else entry = (ushort)(entry >> 1);
|
||||
for(int j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (ushort)((entry >> 1) ^ polynomial);
|
||||
else
|
||||
entry = (ushort)(entry >> 1);
|
||||
|
||||
localTable[i] = entry;
|
||||
}
|
||||
@@ -197,7 +203,7 @@ namespace DiscImageChef.Checksums
|
||||
localhashInt = (ushort)((localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)]);
|
||||
|
||||
BigEndianBitConverter.IsLittleEndian = BitConverter.IsLittleEndian;
|
||||
hash = BigEndianBitConverter.GetBytes(localhashInt);
|
||||
hash = BigEndianBitConverter.GetBytes(localhashInt);
|
||||
|
||||
StringBuilder crc16Output = new StringBuilder();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user