Failed Conditions
Push — master ( 71e756...c4ef0e )
by Florent
08:21 queued 10s
created

JWSBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 7
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sign() 0 12 1
A getAlgorithmMap() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Easy;
15
16
use Jose\Component\Core\AlgorithmManager;
17
use Jose\Component\Core\JWK;
18
use Jose\Component\Core\Util\JsonConverter;
19
use Jose\Component\Signature\Algorithm;
20
use Jose\Component\Signature\JWSBuilder as JoseBuilder;
21
use Jose\Component\Signature\Serializer\CompactSerializer;
22
23
class JWSBuilder extends AbstractBuilder
24
{
25
    public function sign(JWK $jwk): string
26
    {
27
        $builder = new JoseBuilder(new AlgorithmManager($this->algorithms));
28
        $jws = $builder
29
            ->create()
30
            ->withPayload(JsonConverter::encode($this->jwt->claims->all()))
31
            ->addSignature($jwk, $this->jwt->header->all())
32
            ->build()
33
        ;
34
35
        return (new CompactSerializer())->serialize($jws);
36
    }
37
38
    protected function getAlgorithmMap(): array
39
    {
40
        return [
41
            Algorithm\HS256::class,
42
            Algorithm\HS384::class,
43
            Algorithm\HS512::class,
44
            Algorithm\RS256::class,
45
            Algorithm\RS384::class,
46
            Algorithm\RS512::class,
47
            Algorithm\PS256::class,
48
            Algorithm\PS384::class,
49
            Algorithm\PS512::class,
50
            Algorithm\ES256::class,
51
            Algorithm\ES384::class,
52
            Algorithm\ES512::class,
53
            Algorithm\EdDSA::class,
54
        ];
55
    }
56
}
57