BaseHandlerTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 44
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttestationStatementSupportManager() 0 6 1
A getPublicKeyCredentialLoader() 0 5 1
A getDecoder() 0 3 1
A getAttestationObjectLoader() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SilverStripe\WebAuthn;
6
7
use CBOR\Decoder;
8
use CBOR\OtherObject\OtherObjectManager;
9
use CBOR\Tag\TagObjectManager;
10
use Webauthn\AttestationStatement\AttestationObjectLoader;
11
use Webauthn\AttestationStatement\AttestationStatementSupportManager;
12
use Webauthn\AttestationStatement\FidoU2FAttestationStatementSupport;
13
use Webauthn\AttestationStatement\NoneAttestationStatementSupport;
14
use Webauthn\PublicKeyCredentialLoader;
15
16
/**
17
 * Contains logic which is shared between both WebAuthn's RegisterHandler and VerifyHandler, such as
18
 * the attestation configuration options.
19
 */
20
trait BaseHandlerTrait
21
{
22
    /**
23
     * @return Decoder
24
     */
25
    protected function getDecoder(): Decoder
26
    {
27
        return new Decoder(new TagObjectManager(), new OtherObjectManager());
28
    }
29
30
    /**
31
     * @param Decoder $decoder
32
     * @return AttestationStatementSupportManager
33
     */
34
    protected function getAttestationStatementSupportManager(Decoder $decoder): AttestationStatementSupportManager
35
    {
36
        $manager = new AttestationStatementSupportManager();
37
        $manager->add(new NoneAttestationStatementSupport());
38
        $manager->add(new FidoU2FAttestationStatementSupport($decoder));
39
        return $manager;
40
    }
41
42
    /**
43
     * @param AttestationStatementSupportManager $attestationStatementSupportManager
44
     * @param Decoder $decoder
45
     * @return AttestationObjectLoader
46
     */
47
    protected function getAttestationObjectLoader(
48
        AttestationStatementSupportManager $attestationStatementSupportManager,
49
        Decoder $decoder
50
    ): AttestationObjectLoader {
51
        return new AttestationObjectLoader($attestationStatementSupportManager, $decoder);
52
    }
53
54
    /**
55
     * @param AttestationObjectLoader $attestationObjectLoader
56
     * @param Decoder $decoder
57
     * @return PublicKeyCredentialLoader
58
     */
59
    protected function getPublicKeyCredentialLoader(
60
        AttestationObjectLoader $attestationObjectLoader,
61
        Decoder $decoder
62
    ): PublicKeyCredentialLoader {
63
        return new PublicKeyCredentialLoader($attestationObjectLoader, $decoder);
64
    }
65
}
66