mirror of
https://github.com/SabreTools/SabreTools.IO.git
synced 2026-07-08 17:57:02 +00:00
Add CRC-16 and CRC-64 normalization helpers
This commit is contained in:
@@ -65,6 +65,30 @@ namespace SabreTools.Text.Extensions.Test
|
||||
|
||||
#endregion
|
||||
|
||||
#region NormalizeCRC16
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, null)]
|
||||
[InlineData("", "")]
|
||||
[InlineData("-", "")]
|
||||
[InlineData("_", "")]
|
||||
[InlineData("0x", "")]
|
||||
[InlineData("12", "0012")]
|
||||
[InlineData("0x12", "0012")]
|
||||
[InlineData("12ABC", "")]
|
||||
[InlineData("0x12ABC", "")]
|
||||
[InlineData("12AB", "12ab")]
|
||||
[InlineData("0x12AB", "12ab")]
|
||||
[InlineData("aceg", "")]
|
||||
[InlineData("0xaceg", "")]
|
||||
public void NormalizeCRC16Test(string? hash, string? expected)
|
||||
{
|
||||
string? actual = TextHelper.NormalizeCRC16(hash);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NormalizeCRC32
|
||||
|
||||
[Theory]
|
||||
@@ -89,6 +113,30 @@ namespace SabreTools.Text.Extensions.Test
|
||||
|
||||
#endregion
|
||||
|
||||
#region NormalizeCRC64
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, null)]
|
||||
[InlineData("", "")]
|
||||
[InlineData("-", "")]
|
||||
[InlineData("_", "")]
|
||||
[InlineData("0x", "")]
|
||||
[InlineData("1234", "0000000000001234")]
|
||||
[InlineData("0x1234", "0000000000001234")]
|
||||
[InlineData("1234ABCD1234ABCDE", "")]
|
||||
[InlineData("0x1234ABCD1234ABCDE", "")]
|
||||
[InlineData("1234ABCD1234ABCD", "1234abcd1234abcd")]
|
||||
[InlineData("0x1234ABCD1234ABCD", "1234abcd1234abcd")]
|
||||
[InlineData("abcdefghabcdefgh", "")]
|
||||
[InlineData("0xabcdefghabcdefgh", "")]
|
||||
public void NormalizeCRC64Test(string? hash, string? expected)
|
||||
{
|
||||
string? actual = TextHelper.NormalizeCRC64(hash);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region NormalizeMD2
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -70,12 +70,26 @@ namespace SabreTools.Text.Extensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a CRC32 string and pad to the correct size
|
||||
/// Normalize a CRC-16 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <remarks>4 characters long</remarks>
|
||||
public static string? NormalizeCRC16(string? hash)
|
||||
=> NormalizeHashData(hash, 4);
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a CRC-32 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <remarks>8 characters long</remarks>
|
||||
public static string? NormalizeCRC32(string? hash)
|
||||
=> NormalizeHashData(hash, 8);
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a CRC-64 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <remarks>16 characters long</remarks>
|
||||
public static string? NormalizeCRC64(string? hash)
|
||||
=> NormalizeHashData(hash, 16);
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a MD2 string and pad to the correct size
|
||||
/// </summary>
|
||||
@@ -112,28 +126,28 @@ namespace SabreTools.Text.Extensions
|
||||
=> NormalizeHashData(hash, 40);
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a SHA1 string and pad to the correct size
|
||||
/// Normalize a SHA-1 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <remarks>40 characters long</remarks>
|
||||
public static string? NormalizeSHA1(string? hash)
|
||||
=> NormalizeHashData(hash, 40);
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a SHA256 string and pad to the correct size
|
||||
/// Normalize a SHA-256 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <remarks>64 characters long</remarks>
|
||||
public static string? NormalizeSHA256(string? hash)
|
||||
=> NormalizeHashData(hash, 64);
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a SHA384 string and pad to the correct size
|
||||
/// Normalize a SHA-384 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <remarks>96 characters long</remarks>
|
||||
public static string? NormalizeSHA384(string? hash)
|
||||
=> NormalizeHashData(hash, 96);
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a SHA512 string and pad to the correct size
|
||||
/// Normalize a SHA-512 string and pad to the correct size
|
||||
/// </summary>
|
||||
/// <remarks>128 characters long</remarks>
|
||||
public static string? NormalizeSHA512(string? hash)
|
||||
|
||||
Reference in New Issue
Block a user