AesEnum::getKeySize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * File AesEnum.php
4
 */
5
6
namespace Tebru\AesEncryption\Enum;
7
8
use Tebru\AesEncryption\Exception\InvalidMethodException;
9
10
/**
11
 * Class AesEnum
12
 *
13
 * @author Nate Brunette <[email protected]>
14
 */
15
class AesEnum
16
{
17
    const METHOD_128 = 'aes128';
18
    const METHOD_192 = 'aes192';
19
    const METHOD_256 = 'aes256';
20
21
    /**
22
     * Get the key size for an encryption method
23
     *
24
     * @param $method
25
     * @return mixed
26
     */
27
    public static function getKeySize($method)
28
    {
29
        $keySizes = self::getKeySizes();
30
        if (!in_array($method, array_keys($keySizes), true)) {
31
            throw new InvalidMethodException(sprintf('Method "%s" is not a valid AES encryption method', $method));
32
        }
33
34
        return $keySizes[$method];
35
    }
36
37
    /**
38
     * Returns an array keyed by the aes method
39
     *
40
     * @return array
41
     */
42
    private static function getKeySizes()
43
    {
44
        return [
45
            self::METHOD_128 => 16,
46
            self::METHOD_192 => 24,
47
            self::METHOD_256 => 32,
48
        ];
49
    }
50
}
51