PublicKey   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 11 2
A __construct() 0 6 1
1
<?php
2
namespace LibSSH2\Authentication;
3
4
use LibSSH2\Configuration;
5
6
/**
7
 * PublicKey class.
8
 *
9
 * Public key based authentication.
10
 *
11
 * @package LibSSH2\Authentication
12
 */
13
class PublicKey extends Configuration implements Authentication
14
{
15
    /**
16
     * Username.
17
     *
18
     * @var string
19
     */
20
    protected $username;
21
    
22
    /**
23
     * Public key file.
24
     *
25
     * @var string
26
     */
27
    protected $pubkeyfile;
28
    
29
    /**
30
     * Private key file.
31
     *
32
     * @var string
33
     */
34
    protected $privkeyfile;
35
    
36
    /**
37
     * Passphrase.
38
     *
39
     * @var string
40
     */
41
    protected $passphrase;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param  object $configuration Configuration object
47
     * @return void
48
     */
49
    public function __construct(Configuration $configuration)
50
    {
51
        $this->username = $configuration->get_username();
52
        $this->pubkeyfile = $configuration->get_publickey();
53
        $this->privkeyfile = $configuration->get_privatekey();
54
        $this->passphrase = $configuration->get_passphrase();
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    final public function authenticate($resource)
61
    {
62
        if (@ssh2_auth_pubkey_file(
63
            $resource,
64
            $this->username,
65
            $this->pubkeyfile,
66
            $this->privkeyfile,
67
            $this->passphrase
68
        ) === FALSE)
69
        {
70
            throw new \RuntimeException('Public key based authentication failed.');
71
        }
72
    }
73
}
74