You are here

public function LockrEncryptionKeyType::validateKeyValue in Lockr 8.2

Same name and namespace in other branches
  1. 8.4 src/Plugin/KeyType/LockrEncryptionKeyType.php \Drupal\lockr\Plugin\KeyType\LockrEncryptionKeyType::validateKeyValue()
  2. 8.3 src/Plugin/KeyType/LockrEncryptionKeyType.php \Drupal\lockr\Plugin\KeyType\LockrEncryptionKeyType::validateKeyValue()
  3. 4.x src/Plugin/KeyType/LockrEncryptionKeyType.php \Drupal\lockr\Plugin\KeyType\LockrEncryptionKeyType::validateKeyValue()

Allows the Key Type plugin to validate the key value.

Parameters

array $form: An associative array containing the structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the plugin form.

string|null $key_value: The key value to be validated.

Overrides KeyTypeInterface::validateKeyValue

File

src/Plugin/KeyType/LockrEncryptionKeyType.php, line 92

Class

LockrEncryptionKeyType
Defines a key type for encryption that generates keys with Lockr.

Namespace

Drupal\lockr\Plugin\KeyType

Code

public function validateKeyValue(array $form, FormStateInterface $form_state, $key_value) {
  if (!$form_state
    ->getValue('key_size')) {
    return;
  }

  // Validate the key size.
  $bytes = $form_state
    ->getValue('key_size') / 8;
  if (strlen($key_value) != $bytes) {
    $form_state
      ->setErrorByName('key_size', $this
      ->t('The selected key size does not match the actual size of the key.'));
  }
}