REFACTOR: Final cleanup of DiscImageChef.Checksums.

This commit is contained in:
2017-12-23 16:40:14 +00:00
parent d4bfbf2cae
commit bb0b845da8
13 changed files with 251 additions and 232 deletions

View File

@@ -36,18 +36,18 @@ using System.Text;
namespace DiscImageChef.Checksums
{
/// <summary>
/// Implements a CRC64 (ECMA) algorithm
/// Implements a CRC64 (ECMA) algorithm
/// </summary>
public class Crc64Context
{
const ulong CRC64_POLY = 0xC96C5795D7870F42;
const ulong CRC64_SEED = 0xFFFFFFFFFFFFFFFF;
ulong[] table;
ulong hashInt;
ulong[] table;
/// <summary>
/// Initializes the CRC64 table and seed
/// Initializes the CRC64 table and seed
/// </summary>
public void Init()
{
@@ -66,7 +66,7 @@ namespace DiscImageChef.Checksums
}
/// <summary>
/// Updates the hash with data.
/// Updates the hash with data.
/// </summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
@@ -76,7 +76,7 @@ namespace DiscImageChef.Checksums
}
/// <summary>
/// Updates the hash with data.
/// Updates the hash with data.
/// </summary>
/// <param name="data">Data buffer.</param>
public void Update(byte[] data)
@@ -85,7 +85,7 @@ namespace DiscImageChef.Checksums
}
/// <summary>
/// Returns a byte array of the hash value.
/// Returns a byte array of the hash value.
/// </summary>
public byte[] Final()
{
@@ -95,7 +95,7 @@ namespace DiscImageChef.Checksums
}
/// <summary>
/// Returns a hexadecimal representation of the hash value.
/// Returns a hexadecimal representation of the hash value.
/// </summary>
public string End()
{
@@ -103,13 +103,14 @@ namespace DiscImageChef.Checksums
StringBuilder crc64Output = new StringBuilder();
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++) crc64Output.Append(BigEndianBitConverter.GetBytes(hashInt)[i].ToString("x2"));
for(int i = 0; i < BigEndianBitConverter.GetBytes(hashInt).Length; i++)
crc64Output.Append(BigEndianBitConverter.GetBytes(hashInt)[i].ToString("x2"));
return crc64Output.ToString();
}
/// <summary>
/// Gets the hash of a file
/// Gets the hash of a file
/// </summary>
/// <param name="filename">File path.</param>
public static byte[] File(string filename)
@@ -119,7 +120,7 @@ namespace DiscImageChef.Checksums
}
/// <summary>
/// Gets the hash of a file in hexadecimal and as a byte array.
/// Gets the hash of a file in hexadecimal and as a byte array.
/// </summary>
/// <param name="filename">File path.</param>
/// <param name="hash">Byte array of the hash value.</param>
@@ -158,7 +159,7 @@ namespace DiscImageChef.Checksums
}
/// <summary>
/// Gets the hash of the specified data buffer.
/// Gets the hash of the specified data buffer.
/// </summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of the data buffer to hash.</param>
@@ -169,7 +170,7 @@ namespace DiscImageChef.Checksums
}
/// <summary>
/// Gets the hash of the specified data buffer.
/// Gets the hash of the specified data buffer.
/// </summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of the data buffer to hash.</param>
@@ -193,7 +194,8 @@ namespace DiscImageChef.Checksums
localTable[i] = entry;
}
for(int i = 0; i < len; i++) localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)];
for(int i = 0; i < len; i++)
localhashInt = (localhashInt >> 8) ^ localTable[data[i] ^ (localhashInt & 0xff)];
localhashInt ^= CRC64_SEED;
BigEndianBitConverter.IsLittleEndian = BigEndianBitConverter.IsLittleEndian;
@@ -207,7 +209,7 @@ namespace DiscImageChef.Checksums
}
/// <summary>
/// Gets the hash of the specified data buffer.
/// Gets the hash of the specified data buffer.
/// </summary>
/// <param name="data">Data buffer.</param>
/// <param name="hash">Byte array of the hash value.</param>