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

AttestedCredentialData   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCredentialId() 0 3 1
A __construct() 0 5 1
A getAaguid() 0 3 1
A jsonSerialize() 0 11 2
A getCredentialPublicKey() 0 3 1
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 CBOR\MapObject;
17
18
/**
19
 * @see https://www.w3.org/TR/webauthn/#sec-attested-credential-data
20
 */
21
class AttestedCredentialData implements \JsonSerializable
22
{
23
    private $aaguid;
24
25
    private $credentialId;
26
27
    private $credentialPublicKey;
28
29
    public function __construct(string $aaguid, string $credentialId, ?MapObject $credentialPublicKey)
30
    {
31
        $this->aaguid = $aaguid;
32
        $this->credentialId = $credentialId;
33
        $this->credentialPublicKey = $credentialPublicKey;
34
    }
35
36
    public function getAaguid(): string
37
    {
38
        return $this->aaguid;
39
    }
40
41
    public function getCredentialId(): string
42
    {
43
        return $this->credentialId;
44
    }
45
46
    public function getCredentialPublicKey(): ?MapObject
47
    {
48
        return $this->credentialPublicKey;
49
    }
50
51
    public function jsonSerialize()
52
    {
53
        $result = [
54
            'aaguid' => base64_encode($this->aaguid),
55
            'credentialId' => base64_encode($this->credentialId),
56
        ];
57
        if (null !== $this->credentialPublicKey) {
58
            $result['credentialPublicKey'] = base64_encode((string) $this->credentialPublicKey);
59
        }
60
61
        return $result;
62
    }
63
}
64