pub fn check(&mut self, expected: &Hash) -> Result<(), TagError> {
let mut hasher = Hasher::default();
self.file.seek(SeekFrom::Start(0))?;
let mut buf = Vec::new();
// Reading the FileHeader
buf.resize(self.header.header as usize, 0);
self.file.read_exact(&mut buf)?;
hasher.update(&buf);
// Reading the Header
buf.resize((self.header.channel - self.header.header) as usize, 0);
self.file.read_exact(&mut buf)?;
hasher.update(&buf);
// Reading the Header
buf.resize((self.header.unhashed - self.header.channel) as usize, 0);
self.file.read_exact(&mut buf)?;
hasher.update(&buf);
let got = hasher.finish();
if &got != expected {
Err(TagError::WrongHash {
expected: *expected,
got,
})
} else {
Ok(())
}
}