Completed
Push — master ( c20035...05e2ef )
by Florent
05:08
created

None   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 36
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A checkKey() 0 4 1
A sign() 0 6 1
A verify() 0 4 1
A getAlgorithmName() 0 4 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Algorithm\Signature;
13
14
use Assert\Assertion;
15
use Jose\Algorithm\SignatureAlgorithmInterface;
16
use Jose\Object\JWKInterface;
17
18
/**
19
 * This class is an abstract class that implements the none algorithm (plaintext).
20
 */
21
final class None implements SignatureAlgorithmInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function sign(JWKInterface $key, $data)
27
    {
28
        $this->checkKey($key);
29
30
        return '';
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function verify(JWKInterface $key, $data, $signature)
37
    {
38
        return $signature === $this->sign($key, $data);
39
    }
40
41
    /**
42
     * @param JWKInterface $key
43
     */
44
    protected function checkKey(JWKInterface $key)
45
    {
46
        Assertion::eq($key->get('kty'), 'none', 'Wrong key type.');
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getAlgorithmName()
53
    {
54
        return 'none';
55
    }
56
}
57