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

HMACOutputLengthTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validHMACOutputLength() 0 7 2
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