public function JwtHsKeyType::validateKeyValue in JSON Web Token Authentication (JWT) 8
Same name and namespace in other branches
- 8.0 src/Plugin/KeyType/JwtHsKeyType.php \Drupal\jwt\Plugin\KeyType\JwtHsKeyType::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/ JwtHsKeyType.php, line 93
Class
- JwtHsKeyType
- Defines a key type for JWT HMAC Signatures.
Namespace
Drupal\jwt\Plugin\KeyTypeCode
public function validateKeyValue(array $form, FormStateInterface $form_state, $key_value) {
if (!$form_state
->getValue('algorithm')) {
return;
}
// Validate the key size.
$algorithm = $form_state
->getValue('algorithm');
$bytes = self::getAlgorithmKeysize()[$algorithm] / 8;
if (strlen($key_value) < $bytes) {
$form_state
->setErrorByName('algorithm', $this
->t('Key size (%size bits) is too small for algorithm chosen. Algorithm requires a minimum of %required bits.', [
'%size' => strlen($key_value) * 8,
'%required' => $bytes * 8,
]));
}
}