Skip to content

Commit 0075b9b

Browse files
committed
Add CRC-32/DVD-ROM-EDC (fixes #4)
1 parent 214b449 commit 0075b9b

File tree

7 files changed

+28
-3
lines changed

7 files changed

+28
-3
lines changed

SabreTools.Hashing.Test/SpamSumTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ public void FuzzyCompareTest(string? stringOne, string? stringTwo, int expected)
4242
Assert.Equal(expected, result);
4343
}
4444
}
45-
}
45+
}

SabreTools.Hashing.Test/TestHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SabreTools.Hashing.Test
66
/// <summary>
77
/// Helper class for tests
88
/// </summary>
9-
/// CRC values confirmed with <see href="https://emn178.github.io/online-tools/crc/"/>
9+
/// CRC values confirmed with <see href="https://emn178.github.io/online-tools/crc/"/>
1010
internal static class TestHelper
1111
{
1212
#region Known File Information
@@ -143,6 +143,7 @@ internal static class TestHelper
143143
{HashType.CRC32_BZIP2, "18aa4603"},
144144
{HashType.CRC32_CDROMEDC, "b8ced467"},
145145
{HashType.CRC32_CKSUM, "f27b3c27"},
146+
{HashType.CRC32_DVDROMEDC, "b538afc0"},
146147
{HashType.CRC32_ISCSI, "544d37db"},
147148
{HashType.CRC32_ISOHDLC, "ba02a660"},
148149
{HashType.CRC32_JAMCRC, "45fd599f"},
@@ -244,4 +245,4 @@ public static void ValidateHash(HashType hashType, string? hashValue)
244245
public static void ValidateSize(long fileSize)
245246
=> Assert.Equal(_hashFileSize, fileSize);
246247
}
247-
}
248+
}

SabreTools.Hashing/Checksum/StandardDefinitions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,20 @@ public static class StandardDefinitions
14811481
XorOut = 0xffffffff,
14821482
};
14831483

1484+
/// <summary>
1485+
/// CRC-32/DVD-ROM-EDC
1486+
/// </summary>
1487+
public static readonly CrcDefinition CRC32_DVDROMEDC = new()
1488+
{
1489+
Name = "CRC-32/DVD-ROM-EDC",
1490+
Width = 32,
1491+
Poly = 0x80000011,
1492+
Init = 0x00000000,
1493+
ReflectIn = false,
1494+
ReflectOut = false,
1495+
XorOut = 0x00000000,
1496+
};
1497+
14841498
/// <summary>
14851499
/// CRC-32/ISCSI
14861500
/// </summary>

SabreTools.Hashing/Extensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public static class Extensions
138138
HashType.CRC32_BZIP2 => "BZIP2",
139139
HashType.CRC32_CDROMEDC => "CRC-32/CD-ROM-EDC",
140140
HashType.CRC32_CKSUM => "CRC-32/CKSUM",
141+
HashType.CRC32_DVDROMEDC => "CRC-32/DVD-ROM-EDC",
141142
HashType.CRC32_ISCSI => "CRC-32/ISCSI",
142143
HashType.CRC32_ISOHDLC => "CRC-32/ISO-HDLC",
143144
HashType.CRC32_JAMCRC => "CRC-32/JAMCRC",
@@ -364,6 +365,7 @@ public static class Extensions
364365
"crc32_bzip2" => HashType.CRC32_BZIP2,
365366
"crc32_cdromedc" => HashType.CRC32_CDROMEDC,
366367
"crc32_cksum" => HashType.CRC32_CKSUM,
368+
"crc32_dvdromedc" => HashType.CRC32_DVDROMEDC,
367369
"crc32_iscsi" => HashType.CRC32_ISCSI,
368370
"crc32_isohdlc" => HashType.CRC32_ISOHDLC,
369371
"crc32_jamcrc" => HashType.CRC32_JAMCRC,

SabreTools.Hashing/HashType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ public enum HashType
615615
/// </summary>
616616
CRC32_CKSUM,
617617

618+
/// <summary>
619+
/// CRC 32-bit checksum (CRC-32/DVD-ROM-EDC)
620+
/// </summary>
621+
CRC32_DVDROMEDC,
622+
618623
/// <summary>
619624
/// CRC 32-bit checksum (CRC-32/ISCSI)
620625
/// </summary>

SabreTools.Hashing/HashWrapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ private void GetHasher()
208208
HashType.CRC32_BZIP2 => new Crc(StandardDefinitions.CRC32_BZIP2),
209209
HashType.CRC32_CDROMEDC => new Crc(StandardDefinitions.CRC32_CDROMEDC),
210210
HashType.CRC32_CKSUM => new Crc(StandardDefinitions.CRC32_CKSUM),
211+
HashType.CRC32_DVDROMEDC => new Crc(StandardDefinitions.CRC32_DVDROMEDC),
211212
HashType.CRC32_ISCSI => new Crc(StandardDefinitions.CRC32_ISCSI),
212213
HashType.CRC32_ISOHDLC => new Crc(StandardDefinitions.CRC32_ISOHDLC),
213214
HashType.CRC32_JAMCRC => new Crc(StandardDefinitions.CRC32_JAMCRC),

SabreTools.Hashing/ZeroHash.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public static class ZeroHash
221221
{HashType.CRC32_BZIP2, [0x00, 0x00, 0x00, 0x00]},
222222
{HashType.CRC32_CDROMEDC, [0x00, 0x00, 0x00, 0x00]},
223223
{HashType.CRC32_CKSUM, [0xff, 0xff, 0xff, 0xff]},
224+
{HashType.CRC32_DVDROMEDC, [0x00, 0x00, 0x00, 0x00]},
224225
{HashType.CRC32_ISCSI, [0x00, 0x00, 0x00, 0x00]},
225226
{HashType.CRC32_ISOHDLC, [0x00, 0x00, 0x00, 0x00]},
226227
{HashType.CRC32_JAMCRC, [0xff, 0xff, 0xff, 0xff]},
@@ -523,6 +524,7 @@ public static class ZeroHash
523524
{HashType.CRC32_BZIP2, "00000000"},
524525
{HashType.CRC32_CDROMEDC, "00000000"},
525526
{HashType.CRC32_CKSUM, "ffffffff"},
527+
{HashType.CRC32_DVDROMEDC, "00000000"},
526528
{HashType.CRC32_ISCSI, "00000000"},
527529
{HashType.CRC32_ISOHDLC, "00000000"},
528530
{HashType.CRC32_JAMCRC, "ffffffff"},

0 commit comments

Comments
 (0)