1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License (MIT) |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 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\Object; |
13
|
|
|
|
14
|
|
|
use Base64Url\Base64Url; |
15
|
|
|
use Jose\Factory\JWKFactory; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class StorableJWK. |
19
|
|
|
*/ |
20
|
|
|
class StorableJWK implements StorableJWKInterface |
21
|
|
|
{ |
22
|
|
|
use Storable; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $parameters; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* RotatableJWK constructor. |
31
|
|
|
* |
32
|
|
|
* @param string $filename |
33
|
|
|
* @param array $parameters |
34
|
|
|
*/ |
35
|
|
|
public function __construct($filename, array $parameters) |
36
|
|
|
{ |
37
|
|
|
$this->setFilename($filename); |
38
|
|
|
$this->parameters = $parameters; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
public function getFilename() |
45
|
|
|
{ |
46
|
|
|
return $this->filename; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function getAll() |
53
|
|
|
{ |
54
|
|
|
return $this->getJWK()->getAll(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function get($key) |
61
|
|
|
{ |
62
|
|
|
return $this->getJWK()->get($key); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function has($key) |
69
|
|
|
{ |
70
|
|
|
return $this->getJWK()->has($key); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function thumbprint($hash_algorithm) |
77
|
|
|
{ |
78
|
|
|
return $this->getJWK()->thumbprint($hash_algorithm); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function toPublic() |
85
|
|
|
{ |
86
|
|
|
return $this->getJWK()->toPublic(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function jsonSerialize() |
93
|
|
|
{ |
94
|
|
|
return $this->getJWK()->jsonSerialize(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return \Jose\Object\JWKInterface |
99
|
|
|
*/ |
100
|
|
|
protected function getJWK() |
101
|
|
|
{ |
102
|
|
|
$this->loadObjectIfNeeded(); |
103
|
|
|
|
104
|
|
|
return $this->getObject(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
protected function createNewObject() |
108
|
|
|
{ |
109
|
|
|
$data = JWKFactory::createKey($this->parameters)->getAll(); |
110
|
|
|
$data['kid'] = Base64Url::encode(random_bytes(64)); |
111
|
|
|
|
112
|
|
|
return JWKFactory::createFromValues($data); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param array $file_content |
117
|
|
|
* |
118
|
|
|
* @return \JsonSerializable |
119
|
|
|
*/ |
120
|
|
|
protected function createObjectFromFileContent(array $file_content) |
121
|
|
|
{ |
122
|
|
|
return new JWK($file_content); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|