ClientData::getRawData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\Fido;
15
16
use Assert\Assertion;
17
use Base64Url\Base64Url;
18
19
class ClientData
20
{
21
    /**
22
     * @var string
23
     */
24
    private $rawData;
25
26
    /**
27
     * @var string
28
     */
29
    private $typ;
30
31
    /**
32
     * @var string
33
     */
34
    private $challenge;
35
36
    /**
37
     * @var string
38
     */
39
    private $origin;
40
41
    /**
42
     * @var string
43
     */
44
    private $cid_pubkey;
45
46
    public function __construct(string $clientData)
47
    {
48
        $this->rawData = Base64Url::decode($clientData);
49
        $clientData = \Safe\json_decode($this->rawData, true);
50
        Assertion::isArray($clientData, 'Invalid client data.');
51
52
        $diff = array_diff_key(get_class_vars(self::class), $clientData);
53
        unset($diff['rawData'], $diff['cid_pubkey']);
54
55
        Assertion::noContent($diff, 'Invalid client data.');
56
57
        foreach ($clientData as $k => $v) {
58
            $this->$k = $v;
59
        }
60
    }
61
62
    public function getRawData(): string
63
    {
64
        return $this->rawData;
65
    }
66
67
    public function getType(): string
68
    {
69
        return $this->typ;
70
    }
71
72
    public function getChallenge(): string
73
    {
74
        return Base64Url::decode($this->challenge);
75
    }
76
77
    public function getOrigin(): string
78
    {
79
        return $this->origin;
80
    }
81
82
    public function getChannelIdPublicKey(): string
83
    {
84
        return $this->cid_pubkey;
85
    }
86
}
87