public function remainingBytes() : int;
/** * * @param \ParagonIE\Halite\Contract\StreamInterface $fileStream * @param AuthenticationKey $key * @param type $raw * @return type */ public static function checksumStream(StreamInterface $fileStream, KeyInterface $key = null, $raw = false) { $config = self::getConfig(Halite::HALITE_VERSION_FILE, 'checksum'); if ($key) { if (!$key instanceof AuthenticationKey) { throw new \ParagonIE\Halite\Alerts\InvalidKey('Argument 2: Expected an instance of AuthenticationKey'); } $state = \Sodium\crypto_generichash_init($key->get(), $config->HASH_LEN); } else { $state = \Sodium\crypto_generichash_init(null, $config->HASH_LEN); } $size = $fileStream->getSize(); while ($fileStream->remainingBytes() > 0) { $read = $fileStream->readBytes($fileStream->getPos() + $config->BUFFER > $size ? $size - $fileStream->getPos() : $config->BUFFER); \Sodium\crypto_generichash_update($state, $read); } if ($raw) { return \Sodium\crypto_generichash_final($state, $config->HASH_LEN); } return \Sodium\bin2hex(\Sodium\crypto_generichash_final($state, $config->HASH_LEN)); }