You are here

protected function LockrKeyProvider::generateKey in Lockr 8.3

Same name and namespace in other branches
  1. 4.x src/Plugin/KeyProvider/LockrKeyProvider.php \Drupal\lockr\Plugin\KeyProvider\LockrKeyProvider::generateKey()

Creates a new key value, returning it.

1 call to LockrKeyProvider::generateKey()
LockrKeyProvider::getKeyValue in src/Plugin/KeyProvider/LockrKeyProvider.php
Returns the value of a key.

File

src/Plugin/KeyProvider/LockrKeyProvider.php, line 180
Contains Drupal\lockr\Plugin\KeyProvider\LockrKeyProvider.

Class

LockrKeyProvider
Adds a key provider that allows a key to be stored in Lockr.

Namespace

Drupal\lockr\Plugin\KeyProvider

Code

protected function generateKey(KeyInterface $key) {
  $key_type = $key
    ->getKeyType();
  if ($key_type
    ->getPluginId() === 'lockr_encryption') {
    $key_size = (int) $key_type
      ->getConfiguration()['key_size'];
    $new_value = $this->lockr
      ->generateKey($key_size);
    try {
      $this
        ->setKeyValue($key, $new_value);
    } catch (\Exception $e) {
      $this
        ->logException($e);
      return NULL;
    }
    return $new_value;
  }
  return NULL;
}