OpenSSL::verify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php
2
3
namespace EasyPay;
4
5
class OpenSSL
6
{
7
    public function __construct() {}
8
9
    /**
10
     *      verify signature of xml
11
     *
12
     *      @param string $xml
13
     *      @param string $bin_sign
14
     *      @param resource $pub_key
15
     *
16
     *      @return integer result of checking
17
     */
18
    public function verify($xml, $bin_sign, $pub_key)
19
    {
20
        return @openssl_verify($xml, $bin_sign, $pub_key);
21
    }
22
23
    /**
24
     *      generate signature of xml
25
     *
26
     *      @param string $xml
27
     *      @param string $sign
28
     *      @param resource $priv_key
29
     *
30
     *      @return bool result of signing
31
     */
32
    public function sign($xml, &$sign, $priv_key)
33
    {
34
        return @openssl_sign($xml, $sign, $priv_key);
35
    }
36
37
    /**
38
     *      get public key
39
     *
40
     *      @param mixed $certificate
41
     *      @return resource
42
     */
43
    public function get_pub_key($certificate)
44
    {
45
        $pub_key = @openssl_pkey_get_public($certificate);
46
        $this->is_key($pub_key);
47
48
        return $pub_key;
49
    }
50
51
    /**
52
     *      get private key
53
     *
54
     *      @param mixed $certificate
55
     *      @return resource
56
     */
57
    public function get_priv_key($certificate)
58
    {
59
        $priv_key = @openssl_pkey_get_private($certificate);
60
        $this->is_key($priv_key);
0 ignored issues
show
Bug introduced by
It seems like $priv_key can also be of type false; however, parameter $key of EasyPay\OpenSSL::is_key() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
        $this->is_key(/** @scrutinizer ignore-type */ $priv_key);
Loading history...
61
62
        return $priv_key;
63
    }
64
65
    /**
66
     *      check key
67
     *
68
     *      @param resource $key
69
     *      @throws Exception\Runtime
70
     */
71
    public function is_key($key)
72
    {
73
        if ($key === FALSE)
0 ignored issues
show
introduced by
The condition $key === FALSE is always false.
Loading history...
74
        {
75
            throw new Exception\Runtime('Can not extract key from certificate!', -97);
76
        }
77
    }
78
79
}
80