| Total Complexity | 3 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | class SecureIDEncoder extends SimpleIDEncoder |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $secret; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $nonce; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $cipher = 'aes-128-ctr'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param DefinitionRegistry $definitionRegistry |
||
| 36 | * @param Registry $registry |
||
| 37 | * @param string $secret |
||
| 38 | */ |
||
| 39 | 1 | public function __construct(DefinitionRegistry $definitionRegistry, Registry $registry, $secret) |
|
| 45 | 1 | } |
|
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritDoc} |
||
| 49 | */ |
||
| 50 | 1 | public function encode(NodeInterface $node): ?string |
|
| 51 | { |
||
| 52 | 1 | $nodeString = parent::encode($node); |
|
| 53 | 1 | $ciphertext = openssl_encrypt( |
|
| 54 | 1 | $nodeString, |
|
| 55 | 1 | $this->cipher, |
|
| 56 | 1 | $this->secret, |
|
| 57 | 1 | OPENSSL_ZERO_PADDING, |
|
| 58 | 1 | $this->nonce |
|
| 59 | ); |
||
| 60 | |||
| 61 | 1 | return $ciphertext; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritDoc} |
||
| 66 | */ |
||
| 67 | 1 | public function decode($globalId): ?NodeInterface |
|
| 78 | } |
||
| 79 | } |
||
| 80 |