|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File containing the trait {@see \Mailcode\Traits\Commands\Validation\DecryptTrait}. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Mailcode |
|
6
|
|
|
* @subpackage Validation |
|
7
|
|
|
* @see \Mailcode\Traits\Commands\Validation\DecryptTrait |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Mailcode\Traits\Commands\Validation; |
|
13
|
|
|
|
|
14
|
|
|
use Mailcode\Interfaces\Commands\Validation\DecryptInterface; |
|
15
|
|
|
use Mailcode\Mailcode_Commands_Command_ShowVariable; |
|
16
|
|
|
use Mailcode\Mailcode_Commands_Keywords; |
|
17
|
|
|
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral; |
|
18
|
|
|
use function Mailcode\t; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @package Mailcode |
|
22
|
|
|
* @subpackage Validation |
|
23
|
|
|
* @author Olaf Böcker <[email protected]> |
|
24
|
|
|
* |
|
25
|
|
|
* @see DecryptInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
trait DecryptTrait |
|
28
|
|
|
{ |
|
29
|
|
|
private ?Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral $decryptionKeyToken = null; |
|
30
|
|
|
|
|
31
|
|
|
protected function validateSyntax_check_decrypt(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$token = $this->requireParams() |
|
|
|
|
|
|
34
|
|
|
->getInfo() |
|
35
|
|
|
->getTokenForKeyword(Mailcode_Commands_Keywords::TYPE_DECRYPT); |
|
36
|
|
|
|
|
37
|
|
|
if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) { |
|
38
|
|
|
$this->decryptionKeyToken = $token; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$val = $this->validator->createKeyword(Mailcode_Commands_Keywords::TYPE_DECRYPT); |
|
42
|
|
|
|
|
43
|
|
|
if ($this->decryptionKeyToken === null || !$val->isValid()) { |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (!$this->decryptionKeyToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) { |
|
|
|
|
|
|
48
|
|
|
$this->validationResult->makeError( |
|
49
|
|
|
t('Invalid decryption key token:') . ' ' . t('Expected a string.'), |
|
50
|
|
|
DecryptInterface::VALIDATION_DECRYPT_CODE_WRONG_TYPE |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Gets the decryption key to use for the command. If none has |
|
57
|
|
|
* been specified in the original command, the default |
|
58
|
|
|
* decryption key is used as defined via {@see Mailcode_Commands_Command_ShowVariable::setDefaultDecryptionKey()}. |
|
59
|
|
|
* |
|
60
|
|
|
* @return Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getDecryptionKeyToken(): Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral |
|
63
|
|
|
{ |
|
64
|
|
|
if (!isset($this->decryptionKeyToken)) { |
|
65
|
|
|
$this->decryptionKeyToken = $this->createDecryptionKeyToken(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $this->decryptionKeyToken; |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Creates the default decryption key token on demand. |
|
73
|
|
|
* |
|
74
|
|
|
* @return Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral |
|
75
|
|
|
*/ |
|
76
|
|
|
private function createDecryptionKeyToken(): Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral |
|
77
|
|
|
{ |
|
78
|
|
|
$default = Mailcode_Commands_Command_ShowVariable::getDefaultDecryptionKey(); |
|
79
|
|
|
|
|
80
|
|
|
return new Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral( |
|
81
|
|
|
'showvar-decryption-key-token', |
|
82
|
|
|
$default, |
|
83
|
|
|
null, |
|
84
|
|
|
$this |
|
|
|
|
|
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|