class LockrEncryptionKeyType in Lockr 8.4
Same name and namespace in other branches
- 8.2 src/Plugin/KeyType/LockrEncryptionKeyType.php \Drupal\lockr\Plugin\KeyType\LockrEncryptionKeyType
- 8.3 src/Plugin/KeyType/LockrEncryptionKeyType.php \Drupal\lockr\Plugin\KeyType\LockrEncryptionKeyType
- 4.x src/Plugin/KeyType/LockrEncryptionKeyType.php \Drupal\lockr\Plugin\KeyType\LockrEncryptionKeyType
Defines a key type for encryption that generates keys with Lockr.
Plugin annotation
@KeyType(
id = "lockr_encryption",
label = @Translation("Lockr Encryption"),
description = @Translation("A key type used for encryption, generating keys using Townsend AKM."),
group = "encryption",
key_value = {
"plugin" = "generate"
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\key\Plugin\KeyPluginBase implements KeyPluginInterface
- class \Drupal\key\Plugin\KeyTypeBase implements KeyTypeInterface
- class \Drupal\lockr\Plugin\KeyType\LockrEncryptionKeyType implements KeyPluginFormInterface
- class \Drupal\key\Plugin\KeyTypeBase implements KeyTypeInterface
- class \Drupal\key\Plugin\KeyPluginBase implements KeyPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LockrEncryptionKeyType
File
- src/
Plugin/ KeyType/ LockrEncryptionKeyType.php, line 25
Namespace
Drupal\lockr\Plugin\KeyTypeView source
class LockrEncryptionKeyType extends KeyTypeBase implements KeyPluginFormInterface {
/**
* Lockr library client.
*
* @var Lockr
*/
protected $lockr;
/**
* Constructs a new LockrEncryptionKeyType.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param Lockr $lockr
* The Lockr library client.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Lockr $lockr) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->lockr = $lockr;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('lockr.lockr'));
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'key_size' => 256,
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$key_size_options = [
'128' => 128,
'192' => 192,
'256' => 256,
];
$key_size = $this
->getConfiguration()['key_size'];
$form['key_size'] = [
'#type' => 'select',
'#title' => $this
->t('Key size'),
'#description' => $this
->t('The size of the key in bits.'),
'#options' => $key_size_options,
'#default_value' => $key_size,
'#required' => TRUE,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// Default validation is fine.
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this
->setConfiguration($form_state
->getValues());
}
/**
* {@inheritdoc}
*/
public static function generateKeyValue(array $configuration) {
$key_size = $configuration['key_size'];
return \Drupal::service('lockr.lockr')
->generateKey((int) $key_size);
}
/**
* {@inheritdoc}
*/
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.'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
KeyPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
KeyPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
KeyPluginBase:: |
public | function |
Returns the type of plugin. Overrides KeyPluginInterface:: |
|
KeyPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
LockrEncryptionKeyType:: |
protected | property | Lockr library client. | |
LockrEncryptionKeyType:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
LockrEncryptionKeyType:: |
public static | function |
Creates an instance of the plugin. Overrides KeyPluginBase:: |
|
LockrEncryptionKeyType:: |
public | function |
Gets default configuration for this plugin. Overrides KeyPluginBase:: |
|
LockrEncryptionKeyType:: |
public static | function |
Generate a key value of this type using the submitted configuration. Overrides KeyTypeInterface:: |
|
LockrEncryptionKeyType:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
LockrEncryptionKeyType:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
LockrEncryptionKeyType:: |
public | function |
Allows the Key Type plugin to validate the key value. Overrides KeyTypeInterface:: |
|
LockrEncryptionKeyType:: |
public | function |
Constructs a new LockrEncryptionKeyType. Overrides KeyPluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |