Completed
Push — master ( abae97...fc5d0c )
by Breno
03:37 queued 01:48
created

PublicKey::unformated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace XmlSigner;
4
5
class PublicKey implements VerifierInterface
6
{
7
    const SIGNATURE_CORRECT = 1;
8
    const SIGNATURE_INCORRECT = 0;
9
    const SIGNATURE_ERROR = -1;
10
11
    private $key;
12
13 7
    public function __construct(string $key)
14
    {
15 7
        $this->key = $key;
16 7
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 3
    public function verify($data, $signature, $algorithm = OPENSSL_ALGO_SHA1)
22
    {
23 3
        $verified = openssl_verify($data, $signature, $this->key, $algorithm);
24 3
        if ($verified === self::SIGNATURE_ERROR) {
25
            throw CertificateException::invalidSignature();
26
        }
27 3
        return $verified === self::SIGNATURE_CORRECT;
28
    }
29
30
    /**
31
     * Returns unformated public key
32
     * @return string
33
     */
34 2
    public function unformated()
35
    {
36 2
        $ret = preg_replace('/-----.*[\n]?/', '', $this->key);
37 2
        return preg_replace('/[\n\r]/', '', $ret);
38
    }
39
}
40