You are here

public function LockrEncryptionKeyType::validateKeyValue in Lockr 4.x

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

File

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

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