Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
70
core/lib/Drupal/Core/PrivateKey.php
Normal file
70
core/lib/Drupal/Core/PrivateKey.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\PrivateKey.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core;
|
||||
|
||||
use Drupal\Core\State\StateInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
|
||||
/**
|
||||
* Manages the Drupal private key.
|
||||
*/
|
||||
class PrivateKey {
|
||||
|
||||
/**
|
||||
* The state service.
|
||||
*
|
||||
* @var \Drupal\Core\State\StateInterface
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* Constructs the token generator.
|
||||
*
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
* The state service.
|
||||
*/
|
||||
function __construct(StateInterface $state) {
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the private key.
|
||||
*
|
||||
* @return string
|
||||
* The private key.
|
||||
*/
|
||||
public function get() {
|
||||
if (!$key = $this->state->get('system.private_key')) {
|
||||
$key = $this->create();
|
||||
$this->set($key);
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the private key.
|
||||
*
|
||||
* @param string $key
|
||||
* The private key to set.
|
||||
*/
|
||||
public function set($key) {
|
||||
return $this->state->set('system.private_key', $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new private key.
|
||||
*
|
||||
* @return string
|
||||
* The private key.
|
||||
*/
|
||||
protected function create() {
|
||||
return Crypt::randomBytesBase64(55);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue