public function readBytes(int $num, bool $skipTests = false) : string
{
if ($num < 0) {
throw new CryptoException\CannotPerformOperation('num < 0');
} elseif ($num === 0) {
return '';
}
if ($this->pos + $num > $this->stat['size']) {
throw new CryptoException\CannotPerformOperation('Out-of-bounds read');
}
$buf = '';
$remaining = $num;
do {
if ($remaining <= 0) {
break;
}
$read = \fread($this->fp, $remaining);
if ($read === false) {
throw new CryptoException\FileAccessDenied('Could not read from the file');
}
$buf .= $read;
$readSize = CryptoUtil::safeStrlen($read);
$this->pos += $readSize;
$remaining -= $readSize;
} while ($remaining > 0);
return $buf;
}