Passed
Pull Request — master (#60)
by Tim
02:15
created

HMACOutputLengthTrait::validHMACOutputLength()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Assert;
6
7
use InvalidArgumentException;
8
9
/**
10
 * @package simplesamlphp/xml-security
11
 */
12
trait HMACOutputLengthTrait
13
{
14
    /**
15
     * The HMAC algorithm (RFC2104 [HMAC]) takes the output (truncation) length in bits as a parameter;
16
     * this specification REQUIRES that the truncation length be a multiple of 8 (i.e. fall on a byte boundary)
17
     * because Base64 encoding operates on full bytes
18
     *
19
     * @var string
20
     */
21
    private static string $HMACOutputLength_regex = '/^([1-9]\d*)$/D';
22
23
24
    /**
25
     * @param string $value
26
     * @param string $message
27
     */
28
    protected static function validHMACOutputLength(string $value, string $message = ''): void
29
    {
30
        parent::regex(
31
            $value,
32
            self::$HMACOutputLength_regex,
33
            $message ?: '%s is not a valid ds:HMACOutputLengthType',
34
            InvalidArgumentException::class,
35
        );
36
    }
37
}
38