PKCS5AlgorithmIdentifierProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 38
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getClassByOID() 0 7 2
A supportsOID() 0 3 1
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