1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plasma Driver MySQL component |
4
|
|
|
* Copyright 2018-2019 PlasmaPHP, All Rights Reserved |
5
|
|
|
* |
6
|
|
|
* Website: https://github.com/PlasmaPHP |
7
|
|
|
* License: https://github.com/PlasmaPHP/driver-mysql/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Plasma\Drivers\MySQL\Messages; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Represents an Auth Switch Request Message. |
14
|
|
|
*/ |
15
|
|
|
class AuthSwitchRequestMessage implements \Plasma\Drivers\MySQL\Messages\MessageInterface { |
16
|
|
|
/** |
17
|
|
|
* @var string|null |
18
|
|
|
*/ |
19
|
|
|
public $authPluginName; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
public $authPluginData; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \Plasma\Drivers\MySQL\ProtocolParser |
28
|
|
|
* @internal |
29
|
|
|
*/ |
30
|
|
|
protected $parser; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor. |
34
|
|
|
* @param \Plasma\Drivers\MySQL\ProtocolParser $parser |
35
|
|
|
* @internal |
36
|
|
|
*/ |
37
|
4 |
|
function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) { |
38
|
4 |
|
$this->parser = $parser; |
39
|
4 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Get the identifier for the packet. |
43
|
|
|
* @return string |
44
|
|
|
* @internal |
45
|
|
|
*/ |
46
|
1 |
|
static function getID(): string { |
47
|
1 |
|
return "\xFE"; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Parses the message, once the complete string has been received. |
52
|
|
|
* Returns false if not enough data has been received, or the remaining buffer. |
53
|
|
|
* @param \Plasma\BinaryBuffer $buffer |
54
|
|
|
* @return bool |
55
|
|
|
* @throws \Plasma\Drivers\MySQL\Messages\ParseException |
56
|
|
|
* @internal |
57
|
|
|
*/ |
58
|
1 |
|
function parseMessage(\Plasma\BinaryBuffer $buffer): bool { |
59
|
|
|
try { |
60
|
1 |
|
$this->authPluginName = $buffer->readStringNull(); |
61
|
|
|
|
62
|
1 |
|
if($buffer->getSize() > 0) { |
63
|
1 |
|
$this->authPluginData = $buffer->getContents(); |
64
|
1 |
|
$buffer->clear(); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
return true; |
68
|
|
|
} catch (\OverflowException $e) { |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the parser which created this message. |
75
|
|
|
* @return \Plasma\Drivers\MySQL\ProtocolParser |
76
|
|
|
* @internal |
77
|
|
|
*/ |
78
|
1 |
|
function getParser(): \Plasma\Drivers\MySQL\ProtocolParser { |
79
|
1 |
|
return $this->parser; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Sets the parser state, if necessary. If not, return `-1`. |
84
|
|
|
* @return int |
85
|
|
|
* @internal |
86
|
|
|
*/ |
87
|
1 |
|
function setParserState(): int { |
88
|
1 |
|
return \Plasma\Drivers\MySQL\ProtocolParser::STATE_AUTH_SENT; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|