AndroidSafetyNetAttestationStatement   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 73.68%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 50
ccs 14
cts 19
cp 0.7368
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 26 3
A getVersion() 0 3 1
A getResponse() 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\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