AndroidKeyAttestationStatement::getSignature()   A
last analyzed

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\Crypto\CoseAlgorithm;
7
use MadWizard\WebAuthn\Exception\DataValidationException;
8
use MadWizard\WebAuthn\Exception\ParseException;
9
use MadWizard\WebAuthn\Format\ByteBuffer;
10
use MadWizard\WebAuthn\Format\DataValidator;
11
use MadWizard\WebAuthn\Pki\X509Certificate;
12
13
class AndroidKeyAttestationStatement extends AbstractAttestationStatement
14
{
15
    public const FORMAT_ID = 'android-key';
16
17
    /**
18
     * @var ByteBuffer
19
     */
20
    private $signature;
21
22
    /**
23
     * @var X509Certificate[]
24
     */
25
    private $certificates;
26
27
    /**
28
     * @see CoseAlgorithm enumeration
29
     *
30
     * @var int
31
     */
32
    private $algorithm;
33
34 3
    public function __construct(AttestationObject $attestationObject)
35
    {
36 3
        parent::__construct($attestationObject, self::FORMAT_ID);
37
38 3
        $statement = $attestationObject->getStatement();
39
40
        try {
41 3
            DataValidator::checkMap(
42 3
                $statement,
43
                [
44 3
                    'alg' => 'integer',
45
                    'x5c' => 'array',
46
                    'sig' => ByteBuffer::class,
47
                ]
48
            );
49 1
        } catch (DataValidationException $e) {
50 1
            throw new ParseException('Invalid Android key attestation statement.', 0, $e);
51
        }
52
53 2
        $this->signature = $statement->get('sig');
54 2
        $this->algorithm = $statement->get('alg');
55 2
        $this->certificates = $this->buildPEMCertificateArray($statement->get('x5c'));
56 2
    }
57
58 2
    public function getAlgorithm(): int
59
    {
60 2
        return $this->algorithm;
61
    }
62
63 2
    public function getSignature(): ByteBuffer
64
    {
65 2
        return $this->signature;
66
    }
67
68
    /**
69
     * @return X509Certificate[]
70
     */
71 2
    public function getCertificates(): array
72
    {
73 2
        return $this->certificates;
74
    }
75
}
76