2020-08-27 16:57:22 -07:00
|
|
|
|
using System.IO;
|
2025-01-05 21:11:14 -05:00
|
|
|
|
using SabreTools.IO.Extensions;
|
2020-08-27 16:57:22 -07:00
|
|
|
|
|
2020-12-08 14:53:49 -08:00
|
|
|
|
namespace SabreTools.FileTypes.Aaru
|
2020-08-27 16:57:22 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Checksum entry, followed by checksum data itself
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <see cref="https://github.com/aaru-dps/Aaru/blob/master/Aaru.Images/AaruFormat/Structs.cs" />
|
|
|
|
|
|
public class ChecksumEntry
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>Checksum algorithm</summary>
|
|
|
|
|
|
public AaruChecksumAlgorithm type;
|
|
|
|
|
|
/// <summary>Length in bytes of checksum that follows this structure</summary>
|
|
|
|
|
|
public uint length;
|
|
|
|
|
|
/// <summary>Checksum that follows this structure</summary>
|
2024-02-28 19:19:50 -05:00
|
|
|
|
public byte[]? checksum;
|
2020-08-27 16:57:22 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Read a stream as an v
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="stream">ChecksumEntry as a stream</param>
|
|
|
|
|
|
/// <returns>Populated ChecksumEntry, null on failure</returns>
|
2024-02-28 19:19:50 -05:00
|
|
|
|
public static ChecksumEntry? Deserialize(Stream stream)
|
2020-08-27 16:57:22 -07:00
|
|
|
|
{
|
2024-02-28 19:19:50 -05:00
|
|
|
|
var checksumEntry = new ChecksumEntry();
|
2020-08-27 16:57:22 -07:00
|
|
|
|
|
2025-01-05 21:11:14 -05:00
|
|
|
|
checksumEntry.type = (AaruChecksumAlgorithm)stream.ReadByteValue();
|
|
|
|
|
|
checksumEntry.length = stream.ReadUInt32();
|
|
|
|
|
|
if (checksumEntry.length == 0)
|
|
|
|
|
|
return null;
|
2020-08-27 16:57:22 -07:00
|
|
|
|
|
2025-01-05 21:11:14 -05:00
|
|
|
|
checksumEntry.checksum = stream.ReadBytes((int)checksumEntry.length);
|
2020-08-27 16:57:22 -07:00
|
|
|
|
|
|
|
|
|
|
return checksumEntry;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|