SSH2PublicKeyFile::authenticate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 7
cp 0
crap 2
1
<?php
2
3
namespace Dazzle\SSH\Auth;
4
5
use Dazzle\SSH\SSH2AuthInterface;
6
7
/**
8
 * Public key based SSH2 authentication
9
 */
10
class SSH2PublicKeyFile implements SSH2AuthInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $username;
16
17
    /**
18
     * @var string
19
     */
20
    protected $publicKeyFile;
21
22
    /**
23
     * @var string
24
     */
25
    protected $privateKeyFile;
26
27
    /**
28
     * @var null|string
29
     */
30
    protected $passPhrase;
31
32
    /**
33
     * @param string $username The authentication username
34
     * @param string $publicKeyFile The path of the public key file
35
     * @param string $privateKeyFile The path of the private key file
36
     * @param string|null $passPhrase An optional pass phrase for the key
37
     */
38 2
    public function __construct($username, $publicKeyFile, $privateKeyFile, $passPhrase = null)
39
    {
40 2
        $this->username = $username;
41 2
        $this->publicKeyFile = $publicKeyFile;
42 2
        $this->privateKeyFile = $privateKeyFile;
43 2
        $this->passPhrase = $passPhrase;
44 2
    }
45
46
    /**
47
     * @override
48
     * @inheritDoc
49
     */
50
    public function authenticate($conn)
51
    {
52
        return @ssh2_auth_pubkey_file(
53
            $conn,
54
            $this->username,
55
            $this->publicKeyFile,
56
            $this->privateKeyFile,
57
            $this->passPhrase
58
        );
59
    }
60
}
61