Passed
Push — master ( 83aa3d...907404 )
by Thomas
07:17
created

AppleAttestationStatement::getCertificates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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