Passed
Push — master ( 8a38a3...18d115 )
by Dmitry
02:02
created

OpenSSL::get_priv_key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 9.4285
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);
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)
74
        {
75
            throw new Exception\Runtime('Can not extract key from certificate!', -97);
76
        }
77
    }
78
79
}
80