Completed
Pull Request — master (#49)
by Sam
01:29
created

Algorithms::getMnemonic()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of Badcow DNS Library.
5
 *
6
 * (c) Samuel Williams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Badcow\DNS\Rdata;
13
14
/**
15
 * Algorithms listed in {@link https://tools.ietf.org/html/rfc4034#appendix-A.1}.
16
 */
17
class Algorithms
18
{
19
    /**
20
     * RSA/MD5.
21
     */
22
    const RSAMD5 = 1;
23
24
    /**
25
     * Diffie-Hellman.
26
     */
27
    const DH = 2;
28
29
    /**
30
     * DSA/SHA-1.
31
     */
32
    const DSA = 3;
33
34
    /**
35
     * Elliptic Curve.
36
     */
37
    const ECC = 4;
38
39
    /**
40
     * RSA/SHA-1.
41
     */
42
    const RSASHA1 = 5;
43
44
    /**
45
     * Indirect.
46
     */
47
    const INDIRECT = 252;
48
49
    /**
50
     * Private.
51
     */
52
    const PRIVATEDNS = 253;
53
54
    /**
55
     * Private.
56
     */
57
    const PRIVATEOID = 254;
58
59
    /**
60
     * @var array
61
     */
62
    private static $mnemonic = [
63
        self::RSAMD5 => 'RSAMD5',
64
        self::DH => 'DH',
65
        self::DSA => 'DSA',
66
        self::ECC => 'ECC',
67
        self::RSASHA1 => 'RSASHA1',
68
        self::INDIRECT => 'INDIRECT',
69
        self::PRIVATEDNS => 'PRIVATEDNS',
70
        self::PRIVATEOID => 'PRIVATEOID',
71
    ];
72
73
    /**
74
     * Get the associated mnemonic of an algorithm.
75
     *
76
     * @param int $algorithmId
77
     *
78
     * @return string
79
     *
80
     * @throws \InvalidArgumentException
81
     */
82 4
    public static function getMnemonic(int $algorithmId)
83
    {
84 4
        if (!array_key_exists($algorithmId, self::$mnemonic)) {
85 2
            throw new \InvalidArgumentException(sprintf('"%d" id not a valid algorithm.', $algorithmId));
86
        }
87
88 2
        return self::$mnemonic[$algorithmId];
89
    }
90
}
91