1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License (MIT) |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2015 Spomky-Labs |
7
|
|
|
* |
8
|
|
|
* This software may be modified and distributed under the terms |
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Jose; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class JWK. |
16
|
|
|
*/ |
17
|
|
|
class JWK implements JWKInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
protected $values = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* JWK constructor. |
26
|
|
|
* |
27
|
|
|
* @param array $values |
28
|
|
|
*/ |
29
|
|
|
public function __construct(array $values = []) |
30
|
|
|
{ |
31
|
|
|
$this->values = $values; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function getKeyType() |
38
|
|
|
{ |
39
|
|
|
return $this->getValue('kty'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function getPublicKeyUse() |
46
|
|
|
{ |
47
|
|
|
return $this->getValue('use'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function getKeyOperations() |
54
|
|
|
{ |
55
|
|
|
return $this->getValue('key_ops'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function getAlgorithm() |
62
|
|
|
{ |
63
|
|
|
return $this->getValue('alg'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function getKeyID() |
70
|
|
|
{ |
71
|
|
|
return $this->getValue('kid'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
|
|
public function getX509Url() |
78
|
|
|
{ |
79
|
|
|
return $this->getValue('x5u'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
|
|
public function getX509CertificateChain() |
86
|
|
|
{ |
87
|
|
|
return $this->getValue('x5c'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function getX509CertificateSha1Thumbprint() |
94
|
|
|
{ |
95
|
|
|
return $this->getValue('x5t'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritdoc} |
100
|
|
|
*/ |
101
|
|
|
public function getX509CertificateSha256Thumbprint() |
102
|
|
|
{ |
103
|
|
|
return $this->getValue('x5t#256'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function jsonSerialize() |
110
|
|
|
{ |
111
|
|
|
return $this->getValues(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* {@inheritdoc} |
116
|
|
|
*/ |
117
|
|
|
public function getValue($key) |
118
|
|
|
{ |
119
|
|
|
return array_key_exists($key, $this->getValues()) ? $this->values[$key] : null; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* {@inheritdoc} |
124
|
|
|
*/ |
125
|
|
|
public function getValues() |
126
|
|
|
{ |
127
|
|
|
return $this->values; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* {@inheritdoc} |
132
|
|
|
*/ |
133
|
|
|
public function withValue($key, $value) |
134
|
|
|
{ |
135
|
|
|
$jwk = clone $this; |
136
|
|
|
$values = array_merge($this->getValues(), [$key=>$value]); |
137
|
|
|
$jwk->values = $values; |
138
|
|
|
|
139
|
|
|
return $jwk; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|