HS384KeyAnalyzer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A analyze() 0 14 5
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 Base64Url\Base64Url;
17
use Jose\Component\Core\JWK;
18
19
final class HS384KeyAnalyzer implements KeyAnalyzer
20
{
21
    public function analyze(JWK $jwk, MessageBag $bag): void
22
    {
23
        if ('oct' !== $jwk->get('kty')) {
24
            return;
25
        }
26
        if (!$jwk->has('alg') || 'HS384' !== $jwk->get('alg')) {
27
            return;
28
        }
29
        $k = Base64Url::decode($jwk->get('k'));
30
        $kLength = 8 * mb_strlen($k, '8bit');
31
        if ($kLength < 384) {
32
            $bag->add(Message::high('HS384 algorithm requires at least 384 bits key length.'));
33
        }
34
    }
35
}
36