GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

U2fRegistrationFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toFirehed() 0 7 1
A fromFirehed() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LM\AuthAbstractor\Factory;
6
7
use Firehed\U2F\Registration;
8
use LM\AuthAbstractor\Implementation\U2fRegistration;
9
use LM\AuthAbstractor\Model\IU2fRegistration;
10
11
/**
12
 * This class provides methods Firehed U2F registrations into implementations of
13
 * IU2fRegistration, and vice versa.
14
 *
15
 * @internal
16
 */
17
class U2fRegistrationFactory
18
{
19
    /**
20
     * Converts a Firehed U2F Registration instance into an instance of
21
     * IU2fRegistration.
22
     *
23
     * @param Registration $registration A Firehed U2F registration.
24
     * @return IU2fRegistration
25
     */
26
    public function fromFirehed(Registration $registration): IU2fRegistration
27
    {
28
        return new U2fRegistration(
29
            base64_encode($registration->getAttestationCertificateBinary()),
30
            $registration->getCounter(),
31
            base64_encode($registration->getKeyHandleBinary()),
32
            base64_encode($registration->getPublicKey())
33
        )
34
        ;
35
    }
36
37
    /**
38
     * Converts a IU2fRegistration instance into a Firehed Registration
39
     * instance.
40
     *
41
     * @param IU2fRegistration $registration
42
     * @return Registration
43
     */
44
    public function toFirehed(IU2fRegistration $registration): Registration
45
    {
46
        return (new Registration())
47
            ->setAttestationCertificate(base64_decode($registration->getAttestationCertificate(), true))
48
            ->setCounter($registration->getCounter())
49
            ->setKeyHandle(base64_decode($registration->getKeyHandle(), true))
50
            ->setPublicKey(base64_decode($registration->getPublicKey(), true))
51
        ;
52
    }
53
}
54