1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Crypt\Package; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2019 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Limoncello\Contracts\Settings\Packages\SymmetricCryptSettingsInterface; |
22
|
|
|
use function assert; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @package Limoncello\Crypt |
26
|
|
|
*/ |
27
|
|
|
class SymmetricCryptSettings implements SymmetricCryptSettingsInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @inheritdoc |
31
|
|
|
*/ |
32
|
1 |
|
final public function get(array $appConfig): array |
33
|
|
|
{ |
34
|
1 |
|
$defaults = $this->getSettings(); |
35
|
|
|
|
36
|
1 |
|
$password = $defaults[static::KEY_PASSWORD] ?? null; |
37
|
1 |
|
assert(empty($password) === false, "Password cannot be empty."); |
38
|
|
|
|
39
|
1 |
|
return $defaults; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
1 |
|
protected function getSettings(): array |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
1 |
|
static::KEY_METHOD => static::DEFAULT_METHOD, |
49
|
1 |
|
static::KEY_IV => static::DEFAULT_IV, |
50
|
1 |
|
static::KEY_USE_ZERO_PADDING => false, |
51
|
1 |
|
static::KEY_USE_AUTHENTICATION => false, |
52
|
1 |
|
static::KEY_TAG_LENGTH => 16, |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|