|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the MesCryptoBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Francesco Cartenì <http://www.multimediaexperiencestudio.it/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Mes\Security\CryptoBundle; |
|
13
|
|
|
|
|
14
|
|
|
use Defuse\Crypto\Exception\CryptoException as BaseCryptoException; |
|
15
|
|
|
use Defuse\Crypto\Exception\EnvironmentIsBrokenException; |
|
16
|
|
|
use Mes\Security\CryptoBundle\Exception\CryptoException; |
|
17
|
|
|
use Mes\Security\CryptoBundle\Model\KeyInterface; |
|
18
|
|
|
use Mes\Security\CryptoBundle\Model\KeySecretAwareInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class KeyManagerWrapper. |
|
22
|
|
|
*/ |
|
23
|
|
|
class KeyManagerWrapper implements KeyManagerInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var KeyManagerInterface|KeySecretAwareInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $keyManager; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* KeyManagerWrapper constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* @param KeyManagerInterface $keyManager |
|
34
|
|
|
*/ |
|
35
|
8 |
|
public function __construct(KeyManagerInterface $keyManager) |
|
36
|
|
|
{ |
|
37
|
8 |
|
$this->keyManager = $keyManager; |
|
38
|
8 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
* |
|
43
|
|
|
* @throws CryptoException |
|
44
|
|
|
*/ |
|
45
|
2 |
|
public function generate($secret = null) |
|
46
|
|
|
{ |
|
47
|
|
|
try { |
|
48
|
2 |
|
return $this->keyManager->generate($secret); |
|
49
|
1 |
|
} catch (EnvironmentIsBrokenException $ex) { |
|
50
|
1 |
|
throw new CryptoException($ex->getMessage()); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
* |
|
57
|
|
|
* @throws CryptoException |
|
58
|
|
|
*/ |
|
59
|
2 |
|
public function generateFromAscii($key_encoded, $secret = null) |
|
60
|
|
|
{ |
|
61
|
|
|
try { |
|
62
|
2 |
|
return $this->keyManager->generateFromAscii($key_encoded, $secret); |
|
63
|
1 |
|
} catch (BaseCryptoException $ex) { |
|
64
|
1 |
|
throw new CryptoException($ex->getMessage()); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function getKey() |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->keyManager->getKey(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function setKey(KeyInterface $key) |
|
80
|
|
|
{ |
|
81
|
1 |
|
$this->keyManager->setKey($key); |
|
82
|
1 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function getSecret() |
|
88
|
|
|
{ |
|
89
|
1 |
|
return $this->keyManager->getSecret(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function setSecret($secret) |
|
96
|
|
|
{ |
|
97
|
1 |
|
$this->keyManager->setSecret($secret); |
|
98
|
1 |
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|