PKCS5AlgorithmIdentifierProvider::getClassByOID()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\PKCS5\ASN1\AlgorithmIdentifier;
6
7
use Sop\CryptoTypes\AlgorithmIdentifier\AlgorithmIdentifierProvider;
8
9
class PKCS5AlgorithmIdentifierProvider implements AlgorithmIdentifierProvider
10
{
11
    /**
12
     * Mapping from OID to class name.
13
     *
14
     * @var array
15
     */
16
    const MAP_OID_TO_CLASS = [
17
        PBEAlgorithmIdentifier::OID_PBE_WITH_MD2_AND_DES_CBC => PBEWithMD2AndDESCBCAlgorithmIdentifier::class,
18
        PBEAlgorithmIdentifier::OID_PBE_WITH_MD2_AND_RC2_CBC => PBEWithMD2AndRC2CBCAlgorithmIdentifier::class,
19
        PBEAlgorithmIdentifier::OID_PBE_WITH_MD5_AND_DES_CBC => PBEWithMD5AndDESCBCAlgorithmIdentifier::class,
20
        PBEAlgorithmIdentifier::OID_PBE_WITH_MD5_AND_RC2_CBC => PBEWithMD5AndRC2CBCAlgorithmIdentifier::class,
21
        PBEAlgorithmIdentifier::OID_PBE_WITH_SHA1_AND_DES_CBC => PBEWithSHA1AndDESCBCAlgorithmIdentifier::class,
22
        PBEAlgorithmIdentifier::OID_PBE_WITH_SHA1_AND_RC2_CBC => PBEWithSHA1AndRC2CBCAlgorithmIdentifier::class,
23
        PBEAlgorithmIdentifier::OID_PBE_WITH_SHA1_AND_RC2_40_CBC => PBEWithSHA1And40BitRC2CBCAlgorithmIdentifier::class,
24
        PBEAlgorithmIdentifier::OID_PBE_WITH_SHA1_AND_3KEY_3DES_CBC => PBEWithSHA1And3Key3DESCBCAlgorithmIdentifier::class,
25
        PBEAlgorithmIdentifier::OID_PBES2 => PBES2AlgorithmIdentifier::class,
26
        PBKDF2AlgorithmIdentifier::OID_PBKDF2 => PBKDF2AlgorithmIdentifier::class,
27
    ];
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 20
    public function supportsOID(string $oid): bool
33
    {
34 20
        return array_key_exists($oid, self::MAP_OID_TO_CLASS);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 20
    public function getClassByOID(string $oid): string
41
    {
42 20
        if (!$this->supportsOID($oid)) {
43 1
            throw new \UnexpectedValueException(
44 1
                "Algorithm {$oid} is not supported.");
45
        }
46 19
        return self::MAP_OID_TO_CLASS[$oid];
47
    }
48
}
49