ParagonIE\Halite\Stream\ReadOnlyFile::toctouTest PHP Method

toctouTest() public method

Run-time test to prevent TOCTOU attacks (race conditions) through verifying that the hash matches and the current cursor position/file size matches their values when the file was first opened.
public toctouTest ( ) : void
return void
    public function toctouTest()
    {
        if (\ftell($this->fp) !== $this->pos) {
            throw new CryptoException\FileModified('Read-only file has been modified since it was opened for reading');
        }
        $stat = \fstat($this->fp);
        if ($stat['size'] !== $this->stat['size']) {
            throw new CryptoException\FileModified('Read-only file has been modified since it was opened for reading');
        }
    }