Neos\Flow\Security\Cryptography\RsaWalletServicePhp::shutdownObject PHP Method

shutdownObject() public method

Stores the keys array in the keystore file
public shutdownObject ( ) : void
return void
    public function shutdownObject()
    {
        if ($this->saveKeysOnShutdown === false) {
            return;
        }
        $temporaryKeystorePathAndFilename = $this->keystorePathAndFilename . uniqid() . '.temp';
        $result = file_put_contents($temporaryKeystorePathAndFilename, serialize($this->keys));
        if ($result === false) {
            throw new SecurityException('The temporary keystore file "' . $temporaryKeystorePathAndFilename . '" could not be written.', 1305812921);
        }
        $i = 0;
        while (($result = rename($temporaryKeystorePathAndFilename, $this->keystorePathAndFilename)) === false && $i < 5) {
            $i++;
        }
        if ($result === false) {
            throw new SecurityException('The keystore file "' . $this->keystorePathAndFilename . '" could not be written.', 1305812938);
        }
    }

Usage Example

 /**
  * @test
  */
 public function shutdownDoesNotSavesKeysToKeystoreFileIfKeysWereNotModified()
 {
     $this->assertFalse(file_exists('vfs://Foo/EncryptionKey'));
     $keyPairUuid = $this->rsaWalletService->generateNewKeypair(true);
     $this->rsaWalletService->shutdownObject();
     $this->assertTrue(file_exists('vfs://Foo/EncryptionKey'));
     $this->rsaWalletService->initializeObject();
     $this->rsaWalletService->getPublicKey($keyPairUuid);
     // Hack: remove the file so we can actually detect if shutdown() would write it:
     unlink('vfs://Foo/EncryptionKey');
     $this->rsaWalletService->shutdownObject();
     $this->assertFalse(file_exists('vfs://Foo/EncryptionKey'));
 }