[Refactor] General reformat and clean-up.

This commit is contained in:
2025-11-24 20:12:10 +00:00
parent 8331fba1e4
commit a58f2e60e5
415 changed files with 4920 additions and 4829 deletions

View File

@@ -50,7 +50,7 @@
<ItemGroup>
<PackageReference Include="Aaru.Checksums.Native"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection"/>
<PackageReference Include="Sentry" />
<PackageReference Include="Sentry"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Aaru.Generators\Aaru.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>

View File

@@ -83,121 +83,6 @@ public partial class Crc16Context : IChecksum
if(!_useNative) _table = table ?? GenerateTable(polynomial, inverse);
}
#region IChecksum Members
/// <inheritdoc />
public string Name => "Adler-32";
/// <inheritdoc />
public Guid Id => new("D69CF1E7-4A7B-4605-9291-3A1BE4C2951F");
/// <inheritdoc />
public string Author => Authors.NataliaPortillo;
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len)
{
switch(_useNative)
{
case true when _useCcitt:
crc16_ccitt_update(_nativeContext, data, len);
break;
case true when _useIbm:
crc16_update(_nativeContext, data, len);
break;
default:
{
if(_inverse)
StepInverse(ref _hashInt, _table, data, len);
else
Step(ref _hashInt, _table, data, len);
break;
}
}
}
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
public void Update(byte[] data) => Update(data, (uint)data.Length);
/// <inheritdoc />
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
ushort crc = 0;
switch(_useNative)
{
case true when _useCcitt:
crc16_ccitt_final(_nativeContext, ref crc);
crc16_ccitt_free(_nativeContext);
break;
case true when _useIbm:
crc16_final(_nativeContext, ref crc);
crc16_free(_nativeContext);
break;
default:
{
if(_inverse)
crc = (ushort)~(_hashInt ^ _finalSeed);
else
crc = (ushort)(_hashInt ^ _finalSeed);
break;
}
}
return BigEndianBitConverter.GetBytes(crc);
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
var crc16Output = new StringBuilder();
ushort final = 0;
switch(_useNative)
{
case true when _useCcitt:
crc16_ccitt_final(_nativeContext, ref final);
crc16_ccitt_free(_nativeContext);
break;
case true when _useIbm:
crc16_final(_nativeContext, ref final);
crc16_free(_nativeContext);
break;
default:
{
if(_inverse)
final = (ushort)~(_hashInt ^ _finalSeed);
else
final = (ushort)(_hashInt ^ _finalSeed);
break;
}
}
byte[] finalBytes = BigEndianBitConverter.GetBytes(final);
foreach(byte t in finalBytes) crc16Output.Append(t.ToString("x2"));
return crc16Output.ToString();
}
#endregion
[LibraryImport("libAaru.Checksums.Native", SetLastError = true)]
private static partial IntPtr crc16_init();
@@ -632,4 +517,119 @@ public partial class Crc16Context : IChecksum
return localHashInt;
}
#region IChecksum Members
/// <inheritdoc />
public string Name => "Adler-32";
/// <inheritdoc />
public Guid Id => new("D69CF1E7-4A7B-4605-9291-3A1BE4C2951F");
/// <inheritdoc />
public string Author => Authors.NataliaPortillo;
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len)
{
switch(_useNative)
{
case true when _useCcitt:
crc16_ccitt_update(_nativeContext, data, len);
break;
case true when _useIbm:
crc16_update(_nativeContext, data, len);
break;
default:
{
if(_inverse)
StepInverse(ref _hashInt, _table, data, len);
else
Step(ref _hashInt, _table, data, len);
break;
}
}
}
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
public void Update(byte[] data) => Update(data, (uint)data.Length);
/// <inheritdoc />
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
ushort crc = 0;
switch(_useNative)
{
case true when _useCcitt:
crc16_ccitt_final(_nativeContext, ref crc);
crc16_ccitt_free(_nativeContext);
break;
case true when _useIbm:
crc16_final(_nativeContext, ref crc);
crc16_free(_nativeContext);
break;
default:
{
if(_inverse)
crc = (ushort)~(_hashInt ^ _finalSeed);
else
crc = (ushort)(_hashInt ^ _finalSeed);
break;
}
}
return BigEndianBitConverter.GetBytes(crc);
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
var crc16Output = new StringBuilder();
ushort final = 0;
switch(_useNative)
{
case true when _useCcitt:
crc16_ccitt_final(_nativeContext, ref final);
crc16_ccitt_free(_nativeContext);
break;
case true when _useIbm:
crc16_final(_nativeContext, ref final);
crc16_free(_nativeContext);
break;
default:
{
if(_inverse)
final = (ushort)~(_hashInt ^ _finalSeed);
else
final = (ushort)(_hashInt ^ _finalSeed);
break;
}
}
byte[] finalBytes = BigEndianBitConverter.GetBytes(final);
foreach(byte t in finalBytes) crc16Output.Append(t.ToString("x2"));
return crc16Output.ToString();
}
#endregion
}

View File

@@ -47,53 +47,6 @@ public sealed class Md5Context : IChecksum
/// <summary>Initializes the MD5 hash provider</summary>
public Md5Context() => _provider = MD5.Create();
#region IChecksum Members
/// <inheritdoc />
public string Name => Localization.MD5_Name;
/// <inheritdoc />
public Guid Id => new("C78674C4-F699-4FAB-A618-1661AF659A7C");
/// <inheritdoc />
public string Author => Authors.NataliaPortillo;
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) => _provider.TransformBlock(data, 0, (int)len, data, 0);
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
public void Update(byte[] data) => Update(data, (uint)data.Length);
/// <inheritdoc />
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
_provider.TransformFinalBlock([], 0, 0);
return _provider.Hash;
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
_provider.TransformFinalBlock([], 0, 0);
var md5Output = new StringBuilder();
if(_provider.Hash is null) return null;
foreach(byte h in _provider.Hash) md5Output.Append(h.ToString("x2"));
return md5Output.ToString();
}
#endregion
/// <summary>Gets the hash of a file</summary>
/// <param name="filename">File path.</param>
public static byte[] File(string filename)
@@ -142,4 +95,51 @@ public sealed class Md5Context : IChecksum
/// <param name="data">Data buffer.</param>
/// <param name="hash">Byte array of the hash value.</param>
public static string Data(byte[] data, out byte[] hash) => Data(data, (uint)data.Length, out hash);
#region IChecksum Members
/// <inheritdoc />
public string Name => Localization.MD5_Name;
/// <inheritdoc />
public Guid Id => new("C78674C4-F699-4FAB-A618-1661AF659A7C");
/// <inheritdoc />
public string Author => Authors.NataliaPortillo;
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
/// <param name="len">Length of buffer to hash.</param>
public void Update(byte[] data, uint len) => _provider.TransformBlock(data, 0, (int)len, data, 0);
/// <inheritdoc />
/// <summary>Updates the hash with data.</summary>
/// <param name="data">Data buffer.</param>
public void Update(byte[] data) => Update(data, (uint)data.Length);
/// <inheritdoc />
/// <summary>Returns a byte array of the hash value.</summary>
public byte[] Final()
{
_provider.TransformFinalBlock([], 0, 0);
return _provider.Hash;
}
/// <inheritdoc />
/// <summary>Returns a hexadecimal representation of the hash value.</summary>
public string End()
{
_provider.TransformFinalBlock([], 0, 0);
var md5Output = new StringBuilder();
if(_provider.Hash is null) return null;
foreach(byte h in _provider.Hash) md5Output.Append(h.ToString("x2"));
return md5Output.ToString();
}
#endregion
}

View File

@@ -299,8 +299,10 @@ public class ReedSolomon
for(i = _kk - 1; i >= 0; i--)
{
if(_mm != 8)
if(data[i] > _nn)
return -1; /* Illegal symbol */
{
if(data[i] > _nn) return -1;
}
/* Illegal symbol */
int feedback = _indexOf[data[i] ^ bb[_nn - _kk - 1]];
@@ -371,8 +373,10 @@ public class ReedSolomon
for(i = _nn - 1; i >= 0; i--)
{
if(_mm != 8)
if(data[i] > _nn)
return -1; /* Illegal symbol */
{
if(data[i] > _nn) return -1;
}
/* Illegal symbol */
recd[i] = _indexOf[data[i]];
}
@@ -387,8 +391,9 @@ public class ReedSolomon
tmp = 0;
for(j = 0; j < _nn; j++)
if(recd[j] != _a0) /* recd[j] in index form */
tmp ^= _alphaTo[Modnn(recd[j] + (B0 + i - 1) * j)];
{
if(recd[j] != _a0) /* recd[j] in index form */ tmp ^= _alphaTo[Modnn(recd[j] + (B0 + i - 1) * j)];
}
synError |= tmp; /* set flag if non-zero syndrome =>
* error */
@@ -478,8 +483,9 @@ public class ReedSolomon
var discrR = 0;
for(i = 0; i < r; i++)
if(lambda[i] != 0 && s[r - i] != _a0)
discrR ^= _alphaTo[Modnn(_indexOf[lambda[i]] + s[r - i])];
{
if(lambda[i] != 0 && s[r - i] != _a0) discrR ^= _alphaTo[Modnn(_indexOf[lambda[i]] + s[r - i])];
}
discrR = _indexOf[discrR]; /* Index form */
@@ -585,8 +591,9 @@ public class ReedSolomon
j = degLambda < i ? degLambda : i;
for(; j >= 0; j--)
if(s[i + 1 - j] != _a0 && lambda[j] != _a0)
tmp ^= _alphaTo[Modnn(s[i + 1 - j] + lambda[j])];
{
if(s[i + 1 - j] != _a0 && lambda[j] != _a0) tmp ^= _alphaTo[Modnn(s[i + 1 - j] + lambda[j])];
}
if(tmp != 0) degOmega = i;
@@ -604,16 +611,18 @@ public class ReedSolomon
var num1 = 0;
for(i = degOmega; i >= 0; i--)
if(omega[i] != _a0)
num1 ^= _alphaTo[Modnn(omega[i] + i * root[j])];
{
if(omega[i] != _a0) num1 ^= _alphaTo[Modnn(omega[i] + i * root[j])];
}
int num2 = _alphaTo[Modnn(root[j] * (B0 - 1) + _nn)];
var den = 0;
/* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
for(i = Min(degLambda, _nn - _kk - 1) & ~1; i >= 0; i -= 2)
if(lambda[i + 1] != _a0)
den ^= _alphaTo[Modnn(lambda[i + 1] + i * root[j])];
{
if(lambda[i + 1] != _a0) den ^= _alphaTo[Modnn(lambda[i + 1] + i * root[j])];
}
if(den == 0)
{