Failed Conditions
Push — v7 ( 477009...5356df )
by Florent
03:33
created

RsaAnalyzer::analyze()   B

Complexity

Conditions 10
Paths 5

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 7.2765
c 0
b 0
f 0
cc 10
eloc 8
nc 5
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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\KeyAnalyzer;
15
16
use Base64Url\Base64Url;
17
use Jose\Component\Core\JWK;
18
19
final class RsaAnalyzer implements JWKAnalyzerInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function analyze(JWK $jwk, array &$messages)
25
    {
26
        if ('RSA' !== $jwk->get('kty')) {
27
            return;
28
        }
29
        $n = 8 * mb_strlen(Base64Url::decode($jwk->get('n')), '8bit');
30
        if ($n < 2048) {
31
            $messages[] = 'The key length is less than 2048 bits.';
32
        }
33
        if ($jwk->has('d') && (!$jwk->has('p') || !$jwk->has('q') || !$jwk->has('dp') || !$jwk->has('dq') || !$jwk->has('p') || !$jwk->has('qi'))) {
34
            $messages[] = 'The key is a private RSA key, but Chinese Remainder Theorem primes are missing. These primes are not mandatory, but signatures and decryption processes are faster when available.';
35
        }
36
    }
37
}
38