-
-
Notifications
You must be signed in to change notification settings - Fork 596
/
auth_switch_request.js
37 lines (30 loc) · 948 Bytes
/
auth_switch_request.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchRequest
var Packet = require('../packets/packet');
function AuthSwitchRequest (opts)
{
this.pluginName = opts.pluginName;
this.pluginData = opts.pluginData;
}
AuthSwitchRequest.prototype.toPacket = function ()
{
var length = 6 + this.pluginName.length + this.pluginData.length;
var buffer = new Buffer(length);
var packet = new Packet(0, buffer, 0, length);
packet.offset = 4;
packet.writeInt8(0xfe);
packet.writeNullTerminatedString(this.pluginName);
packet.writeBuffer(this.pluginData);
return packet;
};
AuthSwitchRequest.fromPacket = function (packet)
{
var marker = packet.readInt8();
// assert marker == 0xfe?
var name = packet.readNullTerminatedString();
var data = packet.readBuffer();
return new AuthSwitchRequest({
pluginName: name,
pluginData: data
});
};
module.exports = AuthSwitchRequest;