__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0884

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 15
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 26
ccs 11
cts 14
cp 0.7856
crap 3.0884
rs 9.7666
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\ByteBuffer;
9
use MadWizard\WebAuthn\Format\DataValidator;
10
11
class AndroidSafetyNetAttestationStatement extends AbstractAttestationStatement
12
{
13
    public const FORMAT_ID = 'android-safetynet';
14
15
    /**
16
     * @var string
17
     */
18
    private $response;
19
20
    /**
21
     * @var string
22
     */
23
    private $version;
24
25 3
    public function __construct(AttestationObject $attestationObject)
26
    {
27 3
        parent::__construct($attestationObject, self::FORMAT_ID);
28
29 3
        $statement = $attestationObject->getStatement();
30
31
        try {
32 3
            DataValidator::checkMap(
33 3
                $statement,
34
                [
35 3
                    'ver' => 'string',
36
                    'response' => ByteBuffer::class,
37
                ]
38
            );
39
        } catch (DataValidationException $e) {
40
            throw new ParseException('Invalid Android SafetyNet attestation statement.', 0, $e);
41
        }
42
43 3
        $this->version = $statement->get('ver');
44 3
        if ($this->version === '') {
45
            throw new ParseException('Android SafetyNet version is empty.');
46
        }
47
48 3
        $res = $statement->get('response');
49 3
        assert($res instanceof ByteBuffer);
50 3
        $this->response = $res->getBinaryString();
51 3
    }
52
53
    public function getVersion(): string
54
    {
55
        return $this->version;
56
    }
57
58 3
    public function getResponse(): string
59
    {
60 3
        return $this->response;
61
    }
62
}
63