Completed
Push — master ( e2fc6a...8f4253 )
by Tony Karavasilev (Тони
18:35
created

SignatureDigestionTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 19
c 1
b 0
f 0
dl 0
loc 50
ccs 18
cts 18
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSignatureDigestion() 0 3 1
A setSignatureDigestion() 0 30 3
1
<?php
2
3
/**
4
 * Trait implementation of the signature digestion capabilities and actions for asymmetric signature algorithms.
5
 */
6
7
namespace CryptoManana\Core\Traits\MessageEncryption;
8
9
use \CryptoManana\Core\Interfaces\MessageEncryption\SignatureDigestionInterface as SignatureDigestionSpecification;
10
11
/**
12
 * Trait SignatureDigestionTrait - Reusable implementation of `SignatureDigestionInterface`.
13
 *
14
 * @see \CryptoManana\Core\Interfaces\MessageDigestion\SignatureDigestionInterface The abstract specification.
15
 *
16
 * @package CryptoManana\Core\Traits\MessageEncryption
17
 *
18
 * @property int $digestion The signature's internal digestion algorithm property.
19
 *
20
 * @mixin SignatureDigestionSpecification
21
 */
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
Bug introduced by
The constant CryptoManana\Core\Traits...tionTrait::SHA1_SIGNING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
36 32
            self::SHA2_224_SIGNING,
1 ignored issue
show
Bug introduced by
The constant CryptoManana\Core\Traits...Trait::SHA2_224_SIGNING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
37 32
            self::SHA2_256_SIGNING,
1 ignored issue
show
Bug introduced by
The constant CryptoManana\Core\Traits...Trait::SHA2_256_SIGNING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38 32
            self::SHA2_384_SIGNING,
1 ignored issue
show
Bug introduced by
The constant CryptoManana\Core\Traits...Trait::SHA2_384_SIGNING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39 32
            self::SHA2_512_SIGNING,
1 ignored issue
show
Bug introduced by
The constant CryptoManana\Core\Traits...Trait::SHA2_512_SIGNING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
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()
70
    {
71 24
        return $this->digestion;
72
    }
73
}
74