Passed
Push — master ( 1f909f...68b106 )
by Thomas
07:19
created

AuthenticationContext::getUserHandle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MadWizard\WebAuthn\Server\Authentication;
4
5
use MadWizard\WebAuthn\Credential\CredentialId;
6
use MadWizard\WebAuthn\Credential\UserHandle;
7
use MadWizard\WebAuthn\Format\ByteBuffer;
8
use MadWizard\WebAuthn\Server\AbstractContext;
9
use MadWizard\WebAuthn\Server\RequestContext;
10
use MadWizard\WebAuthn\Web\Origin;
11
12
final class AuthenticationContext extends AbstractContext implements RequestContext
13
{
14
    /**
15
     * @var CredentialId[]
16
     */
17
    private $allowCredentialIds = [];
18
19
    /**
20
     * @var UserHandle|null
21
     */
22
    private $userHandle;
23
24 15
    public function __construct(ByteBuffer $challenge, Origin $origin, string $rpId, ?UserHandle $userHandle)
25
    {
26 15
        parent::__construct($challenge, $origin, $rpId);
27 15
        $this->userHandle = $userHandle;
28 15
    }
29
30 15
    public function addAllowCredentialId(CredentialId $credentialId): void
31
    {
32 15
        $this->allowCredentialIds[] = $credentialId;
33 15
    }
34
35 4
    public function getUserHandle(): ?UserHandle
36
    {
37 4
        return $this->userHandle;
38
    }
39
40
    /**
41
     * @return CredentialId[]
42
     */
43 14
    public function getAllowCredentialIds(): array
44
    {
45 14
        return $this->allowCredentialIds;
46
    }
47
48
    public function __serialize(): array
49
    {
50
        return [
51
            'parent' => parent::__serialize(),
52
            'userHandle' => $this->userHandle,
53
            'allowCredentialIds' => $this->allowCredentialIds,
54
        ];
55
    }
56
57
    public function __unserialize(array $data): void
58
    {
59
        parent::__unserialize($data['parent']);
60
        $this->userHandle = $data['userHandle'];
61
        $this->allowCredentialIds = $data['allowCredentialIds'];
62
    }
63
}
64