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 Jose\Component\Encryption; |
15
|
|
|
|
16
|
|
|
use Jose\Component\Checker\HeaderCheckerManagerFactory; |
17
|
|
|
use Jose\Component\Encryption\Serializer\JWESerializerManagerFactory; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class JWELoaderFactory. |
21
|
|
|
*/ |
22
|
|
|
final class JWELoaderFactory |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var JWEDecrypterFactory |
26
|
|
|
*/ |
27
|
|
|
private $jweDecrypterFactory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var JWESerializerManagerFactory |
31
|
|
|
*/ |
32
|
|
|
private $jweSerializerManagerFactory; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var HeaderCheckerManagerFactory|null |
36
|
|
|
*/ |
37
|
|
|
private $headerCheckerManagerFactory = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* JWELoaderFactory constructor. |
41
|
|
|
* |
42
|
|
|
* @param JWESerializerManagerFactory $jweSerializerManagerFactory |
43
|
|
|
* @param JWEDecrypterFactory $jweDecrypterFactory |
44
|
|
|
* @param HeaderCheckerManagerFactory|null $headerCheckerManagerFactory |
45
|
|
|
*/ |
46
|
|
|
public function __construct(JWESerializerManagerFactory $jweSerializerManagerFactory, JWEDecrypterFactory $jweDecrypterFactory, ?HeaderCheckerManagerFactory $headerCheckerManagerFactory) |
47
|
|
|
{ |
48
|
|
|
$this->jweSerializerManagerFactory = $jweSerializerManagerFactory; |
49
|
|
|
$this->jweDecrypterFactory = $jweDecrypterFactory; |
50
|
|
|
$this->headerCheckerManagerFactory = $headerCheckerManagerFactory; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $serializers |
55
|
|
|
* @param array $keyEncryptionAlgorithms |
56
|
|
|
* @param array $contentEncryptionAlgorithms |
57
|
|
|
* @param array $compressionMethods |
58
|
|
|
* @param array $headerCheckers |
59
|
|
|
* |
60
|
|
|
* @return JWELoader |
61
|
|
|
*/ |
62
|
|
|
public function create(array $serializers, array $keyEncryptionAlgorithms, array $contentEncryptionAlgorithms, array $compressionMethods, array $headerCheckers = []): JWELoader |
63
|
|
|
{ |
64
|
|
|
$serializerManager = $this->jweSerializerManagerFactory->create($serializers); |
65
|
|
|
$jweDecrypter = $this->jweDecrypterFactory->create($keyEncryptionAlgorithms, $contentEncryptionAlgorithms, $compressionMethods); |
66
|
|
|
if (null !== $this->headerCheckerManagerFactory) { |
67
|
|
|
$headerCheckerManager = $this->headerCheckerManagerFactory->create($headerCheckers); |
68
|
|
|
} else { |
69
|
|
|
$headerCheckerManager = null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return new JWELoader($serializerManager, $jweDecrypter, $headerCheckerManager); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|