MixedKeyTypes::analyze()   B
last analyzed

Complexity

Conditions 9
Paths 13

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.0555
c 0
b 0
f 0
cc 9
nc 13
nop 2
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\Component\KeyManagement\Analyzer;
15
16
use Jose\Component\Core\JWKSet;
17
18
final class MixedKeyTypes implements KeysetAnalyzer
19
{
20
    public function analyze(JWKSet $jwkset, MessageBag $bag): void
21
    {
22
        if (0 === $jwkset->count()) {
23
            return;
24
        }
25
26
        $hasSymmetricKeys = false;
27
        $hasAsymmetricKeys = false;
28
29
        foreach ($jwkset as $jwk) {
30
            switch ($jwk->get('kty')) {
31
                case 'oct':
32
                    $hasSymmetricKeys = true;
33
34
                    break;
35
                case 'OKP':
36
                case 'RSA':
37
                case 'EC':
38
                    $hasAsymmetricKeys = true;
39
40
                    break;
41
            }
42
        }
43
44
        if ($hasAsymmetricKeys && $hasSymmetricKeys) {
45
            $bag->add(Message::medium('This key set mixes symmetric and assymetric keys.'));
46
        }
47
    }
48
}
49