AppleAttestationStatement   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 40
ccs 12
cts 14
cp 0.8571
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 2
A getCertificates() 0 3 1
1
<?php
2
3
namespace MadWizard\WebAuthn\Attestation\Statement;
4
5
use MadWizard\WebAuthn\Attestation\AttestationObject;
6
use MadWizard\WebAuthn\Exception\DataValidationException;
7
use MadWizard\WebAuthn\Exception\ParseException;
8
use MadWizard\WebAuthn\Format\DataValidator;
9
use MadWizard\WebAuthn\Pki\X509Certificate;
10
11
class AppleAttestationStatement extends AbstractAttestationStatement
12
{
13
    public const FORMAT_ID = 'apple';
14
15
    /**
16
     * @var X509Certificate[]
17
     */
18
    private $certificates;
19
20 2
    public function __construct(AttestationObject $attestationObject)
21
    {
22 2
        parent::__construct($attestationObject, self::FORMAT_ID);
23
24
        // See https://webkit.org/blog/11312/meet-face-id-and-touch-id-for-the-web/
25
26 2
        $statement = $attestationObject->getStatement();
27
28
        // Note: early iOS versions included an 'alg' parameter which was removed later
29
        try {
30 2
            DataValidator::checkMap(
31 2
                $statement,
32
                [
33 2
                    'x5c' => 'array',
34
                ],
35 2
                false
36
            );
37
        } catch (DataValidationException $e) {
38
            throw new ParseException('Invalid apple attestation statement.', 0, $e);
39
        }
40
41 2
        $x5c = $statement->get('x5c');
42 2
        $this->certificates = $this->buildPEMCertificateArray($x5c);
43 2
    }
44
45
    /**
46
     * @return X509Certificate[]
47
     */
48 2
    public function getCertificates(): array
49
    {
50 2
        return $this->certificates;
51
    }
52
}
53