Failed Conditions
Push — master ( 104856...f1eb38 )
by Florent
02:37
created

AuthenticatorAssertionResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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 AuthenticatorAssertionResponse extends AuthenticatorResponse
17
{
18
    /**
19
     * @var string
20
     */
21
    private $authenticatorData;
22
23
    /**
24
     * @var string
25
     */
26
    private $signature;
27
28
    /**
29
     * @var null|string
30
     */
31
    private $userHandle;
32
33
    /**
34
     * AuthenticatorAssertionResponse constructor.
35
     *
36
     * @param string $clientDataJSON
37
     * @param string $authenticatorData
38
     * @param string $signature
39
     * @param string $userHandle
40
     */
41
    public function __construct(string $clientDataJSON, string $authenticatorData, string $signature, string $userHandle)
42
    {
43
        parent::__construct($clientDataJSON);
44
        $this->authenticatorData = $authenticatorData;
45
        $this->signature = $signature;
46
        $this->userHandle = $userHandle;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getAuthenticatorData(): string
53
    {
54
        return $this->authenticatorData;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getSignature(): string
61
    {
62
        return $this->signature;
63
    }
64
65
    /**
66
     * @return null|string
67
     */
68
    public function getUserHandle(): ?string
69
    {
70
        return $this->userHandle;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function jsonSerialize(): array
77
    {
78
        $json = [
79
            'clientDataJSON'    => $this->getClientDataJSON(),
80
            'authenticatorData' => $this->authenticatorData,
81
            'signature'         => $this->signature,
82
        ];
83
        if ($this->userHandle) {
84
            $json['userHandle'] = $this->userHandle;
85
        }
86
87
        return $json;
88
    }
89
}
90