Class: Mysql::Protocol::AuthenticationPacket

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql/protocol.rb

Overview

Authentication packet

Class Method Summary collapse

Class Method Details

.serialize(client_flags, max_packet_size, charset_number, username, scrambled_password, databasename, auth_plugin, connect_attrs) ⇒ Object



783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
# File 'lib/mysql/protocol.rb', line 783

def self.serialize(client_flags, max_packet_size, charset_number, username, scrambled_password, databasename, auth_plugin, connect_attrs)
  data = [
    client_flags,
    max_packet_size,
    charset_number,
    "",                   # always 0x00 * 23
    username,
    Packet.lcs(scrambled_password),
  ]
  pack = "VVCa23Z*A*"
  if databasename
    data.push databasename
    pack.concat "Z*"
  end
  data.push auth_plugin
  pack.concat "Z*"
  attr = connect_attrs.map{|k, v| [Packet.lcs(k.to_s), Packet.lcs(v.to_s)]}.flatten.join
  data.pack(pack) + Packet.lcb(attr.size)+attr
end