Completed
Branch master (48aedc)
by thomas
03:23 queued 02:08
created

SignatureAlgorithmFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getSignatureAlgorithm() 0 17 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bip70\X509;
6
7
use Bip70\Exception\X509Exception;
8
use Sop\CryptoTypes\AlgorithmIdentifier\Feature\AsymmetricCryptoAlgorithmIdentifier;
9
use Sop\CryptoTypes\AlgorithmIdentifier\Feature\SignatureAlgorithmIdentifier;
10
use Sop\CryptoTypes\AlgorithmIdentifier\Hash\SHA1AlgorithmIdentifier;
11
use Sop\CryptoTypes\AlgorithmIdentifier\Hash\SHA256AlgorithmIdentifier;
12
use Sop\CryptoTypes\AlgorithmIdentifier\Signature\SignatureAlgorithmIdentifierFactory;
13
14
class SignatureAlgorithmFactory
15
{
16 6
    public static function getSignatureAlgorithm(
17
        string $pkiType,
18
        AsymmetricCryptoAlgorithmIdentifier $keyAlgorithm
19
    ): SignatureAlgorithmIdentifier {
20 6
        if ($pkiType === PKIType::X509_SHA1) {
21 3
            $hashAlgId = new SHA1AlgorithmIdentifier();
22 5
        } else if ($pkiType === PKIType::X509_SHA256) {
23 3
            $hashAlgId = new SHA256AlgorithmIdentifier();
24
        } else {
25 2
            throw new X509Exception("Unknown signature scheme");
26
        }
27
28 4
        return SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
29 4
            $keyAlgorithm,
30 4
            $hashAlgId
31
        );
32
    }
33
}
34