| Total Complexity | 4 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | trait SignatureDigestionTrait |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Setter for the signature's internal digestion algorithm property. |
||
| 26 | * |
||
| 27 | * @param int $signingAlgorithm The digestion algorithm integer code value. |
||
| 28 | * |
||
| 29 | * @return $this The signature algorithm object. |
||
| 30 | * @throws \Exception Validation errors. |
||
| 31 | */ |
||
| 32 | 16 | public function setSignatureDigestion($signingAlgorithm) |
|
| 33 | { |
||
| 34 | 16 | $validDigestions = [ |
|
| 35 | 16 | self::SHA1_SIGNING, |
|
| 36 | 16 | self::SHA2_224_SIGNING, |
|
| 37 | 16 | self::SHA2_256_SIGNING, |
|
| 38 | 16 | self::SHA2_384_SIGNING, |
|
| 39 | 16 | self::SHA2_512_SIGNING, |
|
| 40 | 16 | ]; |
|
| 41 | |||
| 42 | 16 | $signingAlgorithm = filter_var( |
|
| 43 | 16 | $signingAlgorithm, |
|
| 44 | 16 | FILTER_VALIDATE_INT, |
|
| 45 | 16 | [ |
|
| 46 | 16 | "options" => [ |
|
| 47 | 16 | "min_range" => 1, |
|
| 48 | 16 | "max_range" => PHP_INT_MAX, |
|
| 49 | 16 | ], |
|
| 50 | 16 | ] |
|
| 51 | 16 | ); |
|
| 52 | |||
| 53 | 16 | if ($signingAlgorithm === false || !in_array($signingAlgorithm, $validDigestions, true)) { |
|
| 54 | 4 | throw new \InvalidArgumentException( |
|
| 55 | 4 | 'The digestion algorithm standard must be a valid integer bigger than 0.' |
|
| 56 | 4 | ); |
|
| 57 | } |
||
| 58 | |||
| 59 | 12 | $this->digestion = $signingAlgorithm; |
|
| 60 | |||
| 61 | 12 | return $this; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Setter for the signature's internal digestion algorithm property. |
||
| 66 | * |
||
| 67 | * @return int The digestion algorithm integer code value. |
||
| 68 | */ |
||
| 69 | 12 | public function getSignatureDigestion() |
|
| 72 | } |
||
| 73 | } |
||
| 74 |