2222 */
2323abstract class AbstractAlgorithmFactory
2424{
25+ /**
26+ * A cache of algorithm implementations indexed by algorithm ID.
27+ *
28+ * @var string[]
29+ */
2530 protected static array $ cache = [];
26- protected static bool $ initialized = false ;
27-
2831
2932 /**
30- * An array of blacklisted algorithms .
33+ * Whether the factory has been initialized or not .
3134 *
32- * @var string[]
35+ * @var bool
3336 */
34- protected array $ blacklist = [] ;
37+ protected static bool $ initialized = false ;
3538
3639
3740 /**
@@ -40,12 +43,10 @@ abstract class AbstractAlgorithmFactory
4043 * @param string[]|null $blacklist A list of algorithms forbidden for their use.
4144 * @param string[]|null $defaults A list of known implementations.
4245 */
43- public function __construct (array $ blacklist = null , array $ defaults = null )
44- {
45- if ($ blacklist !== null ) {
46- $ this ->blacklist = $ blacklist ;
47- }
48-
46+ public function __construct (
47+ protected ?array $ blacklist = null ,
48+ ?array $ defaults = null ,
49+ ) {
4950 // initialize the cache for supported algorithms per known implementation
5051 if (!static ::$ initialized && $ defaults !== null ) {
5152 foreach ($ defaults as $ algorithm ) {
@@ -79,8 +80,8 @@ public function __construct(array $blacklist = null, array $defaults = null)
7980 */
8081 public function getAlgorithm (string $ algId , KeyInterface $ key ): AlgorithmInterface
8182 {
82- Assert::true (
83- ! in_array ($ algId , $ this ->blacklist , true ),
83+ Assert::false (
84+ in_array ($ algId , $ this ->blacklist , true ),
8485 sprintf ('Blacklisted algorithm: \'%s \'. ' , $ algId ),
8586 BlacklistedAlgorithmException::class,
8687 );
0 commit comments