You are here

public function EncryptionKeyType::validateKeyValue in Key 8

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/EncryptionKeyType.php, line 117

Class

EncryptionKeyType
Defines a generic key type for encryption.

Namespace

Drupal\key\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.'));
  }
}