public function getHash() : string
{
$init = $this->pos;
\fseek($this->fp, 0, SEEK_SET);
// Create a hash context:
$h = \Sodium\crypto_generichash_init($this->hashKey, \Sodium\CRYPTO_GENERICHASH_BYTES_MAX);
for ($i = 0; $i < $this->stat['size']; $i += self::CHUNK) {
if ($i + self::CHUNK > $this->stat['size']) {
$c = \fread($this->fp, $this->stat['size'] - $i);
} else {
$c = \fread($this->fp, self::CHUNK);
}
\Sodium\crypto_generichash_update($h, $c);
}
// Reset the file pointer's internal cursor to where it was:
\fseek($this->fp, $init, SEEK_SET);
return \Sodium\crypto_generichash_final($h);
}