using System.IO;
using System.Text;
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)
{
var checksumEntry = new ChecksumEntry();
#if NET20 || NET35 || NET40
using (var br = new BinaryReader(stream, Encoding.Default))
#else
using (var br = new BinaryReader(stream, Encoding.Default, true))
#endif
{
checksumEntry.type = (AaruChecksumAlgorithm)br.ReadByte();
checksumEntry.length = br.ReadUInt32();
if (checksumEntry.length == 0)
return null;
checksumEntry.checksum = br.ReadBytes((int)checksumEntry.length);
}
return checksumEntry;
}
}
}