1
|
|
|
<?php namespace security; |
2
|
|
|
/** |
3
|
|
|
* Copyright 2015 OpenStack Foundation |
4
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
5
|
|
|
* you may not use this file except in compliance with the License. |
6
|
|
|
* You may obtain a copy of the License at |
7
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
8
|
|
|
* Unless required by applicable law or agreed to in writing, software |
9
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
10
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
11
|
|
|
* See the License for the specific language governing permissions and |
12
|
|
|
* limitations under the License. |
13
|
|
|
**/ |
14
|
|
|
use jwk\JSONWebKeyTypes; |
15
|
|
|
use utils\ByteUtil; |
16
|
|
|
/** |
17
|
|
|
* Class SymmetricSharedKey |
18
|
|
|
* @package security |
19
|
|
|
*/ |
20
|
|
|
final class SymmetricSharedKey |
21
|
|
|
implements PrivateKey, SharedKey { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param string $secret |
25
|
|
|
*/ |
26
|
|
|
public function __construct($secret){ |
27
|
|
|
$this->secret = $secret; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
private $secret = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
public function getAlgorithm() |
36
|
|
|
{ |
37
|
|
|
return JSONWebKeyTypes::OctetSequence; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function getEncoded() |
44
|
|
|
{ |
45
|
|
|
return $this->getSecret(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
public function getFormat() |
52
|
|
|
{ |
53
|
|
|
return JSONWebKeyTypes::OctetSequence; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return int |
58
|
|
|
*/ |
59
|
|
|
public function getBitLength() |
60
|
|
|
{ |
61
|
|
|
return ByteUtil::bitLength(strlen($this->secret)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getSecret() |
68
|
|
|
{ |
69
|
|
|
return $this->secret; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getStrippedEncoded(): string |
76
|
|
|
{ |
77
|
|
|
return $this->getEncoded(); |
78
|
|
|
} |
79
|
|
|
} |