using System.IO;
using System.Text;
using SabreTools.Core;
namespace SabreTools.FileTypes.Aaru
{
///
/// Checksum entry, followed by checksum data itself
///
///
public class ChecksumEntry
{
/// Checksum algorithm
public AaruChecksumAlgorithm type;
/// Length in bytes of checksum that follows this structure
public uint length;
/// Checksum that follows this structure
public byte[] checksum;
///
/// Read a stream as an v
///
/// ChecksumEntry as a stream
/// Populated ChecksumEntry, null on failure
public static ChecksumEntry Deserialize(Stream stream)
{
ChecksumEntry checksumEntry = new ChecksumEntry();
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
{
checksumEntry.type = (AaruChecksumAlgorithm)br.ReadByte();
checksumEntry.length = br.ReadUInt32();
if (checksumEntry.length == 0)
return null;
checksumEntry.checksum = br.ReadBytes((int)checksumEntry.length);
}
return checksumEntry;
}
}
}