1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Tarantool Client package. |
7
|
|
|
* |
8
|
|
|
* (c) Eugene Leonovich <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Tarantool\Client; |
15
|
|
|
|
16
|
|
|
use Tarantool\Client\Exception\InvalidGreeting; |
17
|
|
|
|
18
|
|
|
final class IProto |
19
|
|
|
{ |
20
|
|
|
public const CODE = 0x00; |
21
|
|
|
public const SYNC = 0x01; |
22
|
|
|
public const SPACE_ID = 0x10; |
23
|
|
|
public const INDEX_ID = 0x11; |
24
|
|
|
public const LIMIT = 0x12; |
25
|
|
|
public const OFFSET = 0x13; |
26
|
|
|
public const ITERATOR = 0x14; |
27
|
|
|
public const KEY = 0x20; |
28
|
|
|
public const TUPLE = 0x21; |
29
|
|
|
public const FUNCTION_NAME = 0x22; |
30
|
|
|
public const USER_NAME = 0x23; |
31
|
|
|
public const EXPR = 0x27; |
32
|
|
|
public const OPERATIONS = 0x28; |
33
|
|
|
public const DATA = 0x30; |
34
|
|
|
public const METADATA = 0x32; |
35
|
|
|
public const ERROR = 0x31; |
36
|
|
|
public const SQL_TEXT = 0x40; |
37
|
|
|
public const SQL_BIND = 0x41; |
38
|
|
|
public const SQL_INFO = 0x42; |
39
|
|
|
|
40
|
|
|
public const GREETING_SIZE = 128; |
41
|
|
|
public const LENGTH_SIZE = 5; |
42
|
|
|
|
43
|
|
|
private function __construct() |
44
|
|
|
{ |
45
|
|
|
} |
46
|
|
|
|
47
|
284 |
|
public static function parseGreeting(string $greeting) : string |
48
|
|
|
{ |
49
|
284 |
|
if (0 !== \strpos($greeting, 'Tarantool')) { |
50
|
42 |
|
throw InvalidGreeting::invalidServerName(); |
51
|
|
|
} |
52
|
|
|
|
53
|
242 |
|
if (false === $salt = \base64_decode(\substr($greeting, 64, 44), true)) { |
54
|
8 |
|
throw InvalidGreeting::invalidSalt(); |
55
|
|
|
} |
56
|
|
|
|
57
|
234 |
|
$salt = \substr($salt, 0, 20); |
58
|
|
|
|
59
|
234 |
|
if (isset($salt[19])) { |
60
|
222 |
|
return $salt; |
61
|
|
|
} |
62
|
|
|
|
63
|
12 |
|
throw InvalidGreeting::invalidSalt(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|