Failed Conditions
Push — master ( ed7204...c7c4bc )
by Florent
01:40
created

PublicKeyCredentialCreationOptions::splitChallenge()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
rs 10
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) 2014-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
use U2FAuthentication\Fido2\AuthenticationExtensions\AuthenticationExtensionsClientInputs;
17
18
class PublicKeyCredentialCreationOptions implements \JsonSerializable
19
{
20
    public const ATTESTATION_CONVEYANCE_PREFERENCE_NONE = 'none';
21
    public const ATTESTATION_CONVEYANCE_PREFERENCE_INDIRECT = 'indirect';
22
    public const ATTESTATION_CONVEYANCE_PREFERENCE_DIRECT = 'direct';
23
24
    private $rp;
25
26
    private $user;
27
28
    private $challenge;
29
30
    /**
31
     * @var PublicKeyCredentialParameters[]
32
     */
33
    private $pubKeyCredParams;
34
35
    private $timeout;
36
37
    /**
38
     * @var PublicKeyCredentialDescriptor[]
39
     */
40
    private $excludeCredentials;
41
42
    private $authenticatorSelection;
43
44
    private $attestation;
45
46
    private $extensions;
47
48
    /**
49
     * PublicKeyCredentialCreationOptions constructor.
50
     *
51
     * @param PublicKeyCredentialParameters[] $pubKeyCredParams
52
     * @param PublicKeyCredentialDescriptor[] $excludeCredentials
53
     */
54
    public function __construct(PublicKeyCredentialRpEntity $rp, PublicKeyCredentialUserEntity $user, string $challenge, array $pubKeyCredParams, ?int $timeout, array $excludeCredentials, AuthenticatorSelectionCriteria $authenticatorSelection, string $attestation, AuthenticationExtensionsClientInputs $extensions)
55
    {
56
        $this->rp = $rp;
57
        $this->user = $user;
58
        $this->challenge = $challenge;
59
        $this->pubKeyCredParams = $pubKeyCredParams;
60
        $this->timeout = $timeout;
61
        $this->excludeCredentials = $excludeCredentials;
62
        $this->authenticatorSelection = $authenticatorSelection;
63
        $this->attestation = $attestation;
64
        $this->extensions = $extensions;
65
    }
66
67
    public function getRp(): PublicKeyCredentialRpEntity
68
    {
69
        return $this->rp;
70
    }
71
72
    public function getUser(): PublicKeyCredentialUserEntity
73
    {
74
        return $this->user;
75
    }
76
77
    public function getChallenge(): string
78
    {
79
        return $this->challenge;
80
    }
81
82
    /**
83
     * @return PublicKeyCredentialParameters[]
84
     */
85
    public function getPubKeyCredParams(): array
86
    {
87
        return $this->pubKeyCredParams;
88
    }
89
90
    public function getTimeout(): ?int
91
    {
92
        return $this->timeout;
93
    }
94
95
    /**
96
     * @return PublicKeyCredentialDescriptor[]
97
     */
98
    public function getExcludeCredentials(): array
99
    {
100
        return $this->excludeCredentials;
101
    }
102
103
    public function getAuthenticatorSelection(): AuthenticatorSelectionCriteria
104
    {
105
        return $this->authenticatorSelection;
106
    }
107
108
    public function getAttestation(): string
109
    {
110
        return $this->attestation;
111
    }
112
113
    public function getExtensions(): AuthenticationExtensionsClientInputs
114
    {
115
        return $this->extensions;
116
    }
117
118
    public function jsonSerialize(): array
119
    {
120
        $json = [
121
            'rp' => $this->rp,
122
            'pubKeyCredParams' => $this->pubKeyCredParams,
123
            'challenge' => base64_encode($this->challenge),
124
            'attestation' => $this->attestation,
125
            'user' => $this->user,
126
            'authenticatorSelection' => $this->authenticatorSelection,
127
        ];
128
129
        if (!empty($this->excludeCredentials)) {
130
            $json['excludeCredentials'] = $this->excludeCredentials;
131
        }
132
133
        if (!empty($this->extensions)) {
134
            $json['extensions'] = $this->extensions;
135
        }
136
137
        if (!\is_null($this->timeout)) {
138
            $json['timeout'] = $this->timeout;
139
        }
140
141
        return $json;
142
    }
143
}
144