1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the tiqr project. |
4
|
|
|
* |
5
|
|
|
* The tiqr project aims to provide an open implementation for |
6
|
|
|
* authentication using mobile devices. It was initiated by |
7
|
|
|
* SURFnet and developed by Egeniq. |
8
|
|
|
* |
9
|
|
|
* More information: http://www.tiqr.org |
10
|
|
|
* |
11
|
|
|
* @author Peter Verhage <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @package tiqr |
14
|
|
|
* |
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
16
|
|
|
* |
17
|
|
|
* @copyright (C) 2010-2012 SURFnet BV |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
use Psr\Log\LoggerInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class implementing a factory for user storage encryption. |
24
|
|
|
* |
25
|
|
|
* @author peter |
26
|
|
|
*/ |
27
|
|
|
class Tiqr_UserSecretStorage_Encryption |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Get an encryption handler of a certain type (default: 'dummy') |
31
|
|
|
* |
32
|
|
|
* @param LoggerInterface $logger |
33
|
|
|
* @param String $type The type of storage to create. Supported types are 'dummy' (default) |
34
|
|
|
* or any class implementing Tiqr_UserSecretStorage_Encryption_Interface. |
35
|
|
|
* In that case $type should be the full class name. |
36
|
|
|
* @param array $options The options to pass to the storage instance. See the documentation |
37
|
|
|
* in the Encryption subdirectory for options per type. |
38
|
|
|
* |
39
|
|
|
* @return Tiqr_UserSecretStorage_Encryption_Interface |
40
|
|
|
*/ |
41
|
22 |
|
public static function getEncryption(LoggerInterface $logger, string $type="dummy", array $options=array()): Tiqr_UserSecretStorage_Encryption_Interface |
42
|
|
|
{ |
43
|
22 |
|
$instance = null; |
44
|
22 |
|
$logger->info(sprintf('Using "%s" as UserSecretStorage encryption type', $type)); |
45
|
22 |
|
switch ($type) { |
46
|
22 |
|
case "dummy": |
47
|
21 |
|
case "plain": |
48
|
15 |
|
$instance = new Tiqr_UserSecretStorage_Encryption_Plain($options); |
49
|
15 |
|
break; |
50
|
10 |
|
case "openssl": |
51
|
7 |
|
$instance = new Tiqr_UserSecretStorage_Encryption_OpenSSL($options); |
52
|
4 |
|
break; |
53
|
|
|
default: |
54
|
5 |
|
if (class_exists($type)) { |
55
|
4 |
|
$instance = new $type($options); |
56
|
|
|
} else { |
57
|
1 |
|
throw new RuntimeException(sprintf("Class '%s' not found", $type)); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
18 |
|
return $instance; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|