Passed
Pull Request — master (#43)
by Tim
02:10
created

AsymmetricKey   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPEM() 0 3 1
A __construct() 0 3 1
A getMaterial() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Key;
6
7
use OpenSSLAsymmetricKey;
8
use SimpleSAML\XMLSecurity\CryptoEncoding\PEM;
9
10
/**
11
 * A class representing an asymmetric key.
12
 *
13
 * This class can be extended to implement public or private keys.
14
 *
15
 * @package simplesamlphp/xml-security
16
 */
17
abstract class AsymmetricKey implements KeyInterface
18
{
19
    /** @var \SimpleSAML\XMLSecurity\CryptoEncoding\PEM */
20
    protected PEM $material;
21
22
23
    /**
24
     * Build a new key with $key as its material.
25
     *
26
     * @param \SimpleSAML\XMLSecurity\CryptoEncoding\PEM $key The associated key material.
27
     */
28
    public function __construct(PEM $key)
29
    {
30
        $this->material = $key;
31
    }
32
33
34
    /**
35
     * Return the key material associated with this key.
36
     *
37
     * @return string The key material.
38
     */
39
    public function getMaterial(): string
40
    {
41
        return $this->material->string();
42
    }
43
44
45
    /**
46
     * Return the raw PEM-object associated with this key.
47
     *
48
     * @return \SimpleSAML\XMLSecurity\CryptoEncoding\PEM The raw material.
49
     */
50
    public function getPEM(): PEM
51
    {
52
        return $this->material;
53
    }
54
}
55