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

RsaAnalyzer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 2
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B analyze() 0 13 10
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