SSH2HostBasedFile   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 47.06%

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
ccs 8
cts 17
cp 0.4706
wmc 2
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A authenticate() 0 12 1
1
<?php
2
3
namespace Dazzle\SSH\Auth;
4
5
use Dazzle\SSH\SSH2AuthInterface;
6
7
/**
8
 * Host based SSH2 authentication.
9
 */
10
class SSH2HostBasedFile implements SSH2AuthInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $username;
16
17
    /**
18
     * @var string
19
     */
20
    protected $hostname;
21
22
    /**
23
     * @var string
24
     */
25
    protected $publicKeyFile;
26
27
    /**
28
     * @var string
29
     */
30
    protected $privateKeyFile;
31
32
    /**
33
     * @var null|string
34
     */
35
    protected $passPhrase;
36
37
    /**
38
     * @var null|string
39
     */
40
    protected $localUsername;
41
42
    /**
43
     * @param string $username The authentication username
44
     * @param string $hostname The authentication hostname
45
     * @param string $publicKeyFile The path of the public key file
46
     * @param string $privateKeyFile The path of the private key file
47
     * @param string $passPhrase An optional pass phrase for the key
48
     * @param string $localUsername  An optional local usernale. If omitted, the username will be used
49
     */
50 2
    public function __construct($username, $hostname, $publicKeyFile, $privateKeyFile, $passPhrase = null, $localUsername = null)
51
    {
52 2
        $this->username = $username;
53 2
        $this->hostname = $hostname;
54 2
        $this->publicKeyFile = $publicKeyFile;
55 2
        $this->privateKeyFile = $privateKeyFile;
56 2
        $this->passPhrase = $passPhrase;
57 2
        $this->localUsername = $localUsername;
58 2
    }
59
60
    /**
61
     * @override
62
     * @inheritDoc
63
     */
64
    public function authenticate($conn)
65
    {
66
        return @ssh2_auth_hostbased_file(
67
            $conn,
68
            $this->username,
69
            $this->hostname,
70
            $this->publicKeyFile,
71
            $this->privateKeyFile,
72
            $this->passPhrase,
73
            $this->localUsername
74
        );
75
    }
76
}
77