ExtensionHelper::validExtensionIdentifier()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace MadWizard\WebAuthn\Extension;
4
5
final class ExtensionHelper
6
{
7
    public const MAX_IDENTIFIER_LENGHT = 32;
8
9 15
    public static function validExtensionIdentifier(string $identifier): bool
10
    {
11
        // SPEC 9.1
12
        // All extension identifiers MUST be a maximum of 32 octets in length and MUST consist only of printable
13
        // USASCII characters, excluding backslash and doublequote, i.e., VCHAR as defined in [RFC5234] but without
14
        // %x22 and %x5c. Implementations MUST match WebAuthn extension identifiers in a case-sensitive fashion.
15 15
        if (strlen($identifier) > self::MAX_IDENTIFIER_LENGHT) {
16 1
            return false;
17
        }
18 15
        return (bool) preg_match('~^[\x21\x23-\x5B\x5D-\x7E]+$~', $identifier);
19
    }
20
}
21