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

SignatureAlgorithmFactory::getSignatureAlgorithm()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 13
nc 3
nop 2
crap 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