| Total Complexity | 5 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | trait SecretKeyTrait |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Setter for the secret key string property. |
||
| 26 | * |
||
| 27 | * @param string $key The encryption key string. |
||
| 28 | * |
||
| 29 | * @return $this The encryption algorithm object. |
||
| 30 | * @throws \Exception Validation errors. |
||
| 31 | */ |
||
| 32 | public function setSecretKey($key) |
||
| 33 | { |
||
| 34 | if (!is_string($key)) { |
||
|
1 ignored issue
–
show
|
|||
| 35 | throw new \InvalidArgumentException('The secret key must be a string or a binary string.'); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * {@internal The encryption standard is 8-bit wise (don not use StringBuilder) and utilizes performance. }} |
||
| 40 | */ |
||
| 41 | if (strlen($key) > static::KEY_SIZE) { |
||
|
1 ignored issue
–
show
|
|||
| 42 | $key = hash_hkdf('sha256', $key, static::KEY_SIZE, 'CryptoMañana', ''); |
||
| 43 | } elseif (strlen($key) < static::KEY_SIZE) { |
||
| 44 | $key = str_pad($key, static::KEY_SIZE, "\x0", STR_PAD_RIGHT); |
||
| 45 | } |
||
| 46 | |||
| 47 | $this->key = $key; |
||
| 48 | |||
| 49 | return $this; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Getter for the secret key string property. |
||
| 54 | * |
||
| 55 | * @return string The encryption key string. |
||
| 56 | */ |
||
| 57 | public function getSecretKey() |
||
| 60 | } |
||
| 61 | } |
||
| 62 |