2020-08-27 16:57:22 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
2020-12-08 13:23:59 -08:00
|
|
|
|
using SabreTools.Core;
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-02-28 21:59:13 -05:00
|
|
|
|
#if NET20 || NET35 || NET40
|
|
|
|
|
|
using (var br = new BinaryReader(stream, Encoding.Default))
|
|
|
|
|
|
#else
|
2024-02-28 19:19:50 -05:00
|
|
|
|
using (var br = new BinaryReader(stream, Encoding.Default, true))
|
2024-02-28 21:59:13 -05:00
|
|
|
|
#endif
|
2020-08-27 16:57:22 -07:00
|
|
|
|
{
|
|
|
|
|
|
checksumEntry.type = (AaruChecksumAlgorithm)br.ReadByte();
|
|
|
|
|
|
checksumEntry.length = br.ReadUInt32();
|
|
|
|
|
|
if (checksumEntry.length == 0)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
checksumEntry.checksum = br.ReadBytes((int)checksumEntry.length);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return checksumEntry;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|