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 | 32 | public function setSignatureDigestion($signingAlgorithm) |
|
33 | { |
||
34 | $validDigestions = [ |
||
35 | 32 | self::SHA1_SIGNING, |
|
1 ignored issue
–
show
|
|||
36 | 32 | self::SHA2_224_SIGNING, |
|
1 ignored issue
–
show
|
|||
37 | 32 | self::SHA2_256_SIGNING, |
|
1 ignored issue
–
show
|
|||
38 | 32 | self::SHA2_384_SIGNING, |
|
1 ignored issue
–
show
|
|||
39 | 32 | self::SHA2_512_SIGNING, |
|
1 ignored issue
–
show
|
|||
40 | ]; |
||
41 | |||
42 | 32 | $signingAlgorithm = filter_var( |
|
43 | 32 | $signingAlgorithm, |
|
44 | 32 | FILTER_VALIDATE_INT, |
|
45 | [ |
||
46 | "options" => [ |
||
47 | 32 | "min_range" => 1, |
|
48 | 32 | "max_range" => PHP_INT_MAX, |
|
49 | ], |
||
50 | ] |
||
51 | ); |
||
52 | |||
53 | 32 | if ($signingAlgorithm === false || !in_array($signingAlgorithm, $validDigestions, true)) { |
|
54 | 8 | throw new \InvalidArgumentException( |
|
55 | 8 | 'The digestion algorithm standard must be a valid integer bigger than 0.' |
|
56 | ); |
||
57 | } |
||
58 | |||
59 | 24 | $this->digestion = $signingAlgorithm; |
|
60 | |||
61 | 24 | 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 | 24 | public function getSignatureDigestion() |
|
72 | } |
||
73 | } |
||
74 |