Completed
Push — master ( 7aad34...96e43e )
by Florent
02:35
created

Dir::getKeyManagementMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\KeyEncryption;
13
14
use Base64Url\Base64Url;
15
use Jose\Object\JWKInterface;
16
17
final class Dir implements DirectEncryptionInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function getCEK(JWKInterface $key)
23
    {
24
        if ('dir' !== $key->get('kty') || !$key->has('dir')) {
25
            throw new \InvalidArgumentException('The key is not valid');
26
        }
27
28
        return Base64Url::decode($key->get('dir'));
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getAlgorithmName()
35
    {
36
        return 'dir';
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getKeyManagementMode()
43
    {
44
        return self::MODE_DIRECT;
45
    }
46
}
47