@@ -60,16 +60,16 @@ final class EncryptionAlgorithmFactory
60
60
/**
61
61
* Build a factory that creates algorithms.
62
62
*
63
- * @param string[]|null $blacklist A list of algorithms forbidden for their use.
63
+ * @param string[] $blacklist A list of algorithms forbidden for their use.
64
64
*/
65
65
public function __construct (
66
- protected ? array $ blacklist = self ::DEFAULT_BLACKLIST ,
66
+ protected array $ blacklist = self ::DEFAULT_BLACKLIST ,
67
67
) {
68
68
// initialize the cache for supported algorithms per known implementation
69
- if (!self ::$ initialized && $ blacklist !== null ) {
69
+ if (!self ::$ initialized ) {
70
70
foreach (self ::SUPPORTED_DEFAULTS as $ algorithm ) {
71
71
foreach ($ algorithm ::getSupportedAlgorithms () as $ algId ) {
72
- if (array_key_exists ($ algId , self ::$ cache )) {
72
+ if (array_key_exists ($ algId , self ::$ cache ) && ! array_key_exists ( $ algId , $ this -> blacklist ) ) {
73
73
/*
74
74
* If the key existed before initialization, that means someone registered a handler for this
75
75
* algorithm, so we should respect that and skip registering the default here.
@@ -101,8 +101,9 @@ public function getAlgorithm(
101
101
#[\SensitiveParameter]
102
102
KeyInterface $ key ,
103
103
): EncryptionAlgorithmInterface {
104
- Assert::false (
105
- ($ this ->blacklist !== null ) && in_array ($ algId , $ this ->blacklist , true ),
104
+ Assert::notInArray (
105
+ $ algId ,
106
+ $ this ->blacklist ,
106
107
sprintf ('Blacklisted algorithm: \'%s \'. ' , $ algId ),
107
108
BlacklistedAlgorithmException::class,
108
109
);
0 commit comments