Failed Conditions
Push — master ( bbfade...32fb37 )
by Florent
02:44
created

AuthenticatorAttestationResponse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAttestationObject() 0 3 1
A jsonSerialize() 0 5 1
A createFromJson() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace U2FAuthentication\Fido2;
15
16
class AuthenticatorAttestationResponse extends AuthenticatorResponse
17
{
18
    /**
19
     * @var string
20
     */
21
    private $attestationObject;
22
23
    /**
24
     * AuthenticatorAttestationResponse constructor.
25
     *
26
     * @param string $clientDataJSON
27
     * @param string $attestationObject
28
     */
29
    public function __construct(string $clientDataJSON, string $attestationObject)
30
    {
31
        parent::__construct($clientDataJSON);
32
        $this->attestationObject = $attestationObject;
33
    }
34
35
    /**
36
     * @param array $json
37
     *
38
     * @return AuthenticatorAttestationResponse
39
     */
40
    public static function createFromJson(array $json): self
41
    {
42
        if (!array_key_exists('clientDataJSON', $json)) {
43
            throw new \InvalidArgumentException();
44
        }
45
        if (!array_key_exists('attestationObject', $json)) {
46
            throw new \InvalidArgumentException();
47
        }
48
49
        return new self(
50
            $json['clientDataJSON'],
51
            $json['attestationObject']
52
        );
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getAttestationObject(): string
59
    {
60
        return $this->attestationObject;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function jsonSerialize(): array
67
    {
68
        return [
69
            'clientDataJSON'    => $this->getClientDataJSON(),
70
            'attestationObject' => $this->attestationObject,
71
        ];
72
    }
73
}
74