Passed
Pull Request — master (#60)
by Tim
02:40 queued 23s
created

HMACOutputLengthTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A validHMACOutputLength() 0 19 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Assert;
6
7
use SimpleSAML\XML\Exception\SchemaViolationException;
8
use SimpleSAML\XMLSecurity\Exception\ProtocolViolationException;
9
10
use function intval;
11
12
/**
13
 * @package simplesamlphp/xml-security
14
 */
15
trait HMACOutputLengthTrait
16
{
17
    /**
18
     * The HMAC algorithm (RFC2104 [HMAC]) takes the output (truncation) length in bits as a parameter;
19
     * this specification REQUIRES that the truncation length be a multiple of 8 (i.e. fall on a byte boundary)
20
     * because Base64 encoding operates on full bytes
21
     *
22
     * @var string
23
     */
24
    private static string $HMACOutputLength_regex = '/^([1-9]\d*)$/D';
25
26
27
    /**
28
     * @param string $value
29
     * @param string $message
30
     */
31
    protected static function validHMACOutputLength(string $value, string $message = ''): void
32
    {
33
        try {
34
            parent::regex(
35
                $value,
36
                self::$HMACOutputLength_regex,
37
                $message ?: '%s is not a valid ds:HMACOutputLengthType',
38
            );
39
        } catch (AssertionFailedException $e) {
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\A...ssertionFailedException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
            throw new SchemaViolationException($e->getMessage());
41
        }
42
43
        try {
44
            parent::true(
45
                intval($value) % 8 === 0,
46
                '%s is not devisible by 8 and therefore not a valid ds:HMACOutputLengthType',
47
            );
48
        } catch (AssertionFailedException $e) {
49
            throw new ProtocolViolationException($e->getMessage());
50
        }
51
52
    }
53
}
54