Class: Mysql::Protocol::InitialPacket

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

Overview

Initial packet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ InitialPacket

Returns a new instance of InitialPacket.



354
355
356
# File 'lib/mysql/protocol.rb', line 354

def initialize(*args)
  @protocol_version, @server_version, @thread_id, @server_capabilities, @server_charset, @server_status, @scramble_buff = args
end

Instance Attribute Details

#protocol_versionObject

Returns the value of attribute protocol_version.



352
353
354
# File 'lib/mysql/protocol.rb', line 352

def protocol_version
  @protocol_version
end

#scramble_buffObject

Returns the value of attribute scramble_buff.



352
353
354
# File 'lib/mysql/protocol.rb', line 352

def scramble_buff
  @scramble_buff
end

#server_capabilitiesObject

Returns the value of attribute server_capabilities.



352
353
354
# File 'lib/mysql/protocol.rb', line 352

def server_capabilities
  @server_capabilities
end

#server_charsetObject

Returns the value of attribute server_charset.



352
353
354
# File 'lib/mysql/protocol.rb', line 352

def server_charset
  @server_charset
end

#server_statusObject

Returns the value of attribute server_status.



352
353
354
# File 'lib/mysql/protocol.rb', line 352

def server_status
  @server_status
end

#server_versionObject

Returns the value of attribute server_version.



352
353
354
# File 'lib/mysql/protocol.rb', line 352

def server_version
  @server_version
end

#thread_idObject

Returns the value of attribute thread_id.



352
353
354
# File 'lib/mysql/protocol.rb', line 352

def thread_id
  @thread_id
end

Class Method Details

.parse(data) ⇒ Object

Raises:



341
342
343
344
345
346
347
348
349
350
# File 'lib/mysql/protocol.rb', line 341

def self.parse(data)
  protocol_version, server_version, thread_id, scramble_buff, f0,
  server_capabilities, server_charset, server_status, f1,
  rest_scramble_buff = data.unpack("CZ*Va8CvCva13Z13")
  raise ProtocolError, "unsupported version: #{protocol_version}" unless protocol_version == VERSION
  raise ProtocolError, "invalid packet: f0=#{f0}" unless f0 == 0
  raise ProtocolError, "invalid packet: f1=#{f1.inspect}" unless f1 == "\0\0\0\0\0\0\0\0\0\0\0\0\0"
  scramble_buff.concat rest_scramble_buff
  self.new protocol_version, server_version, thread_id, server_capabilities, server_charset, server_status, scramble_buff
end

Instance Method Details

#crypt_password(plain) ⇒ Object



358
359
360
361
362
363
# File 'lib/mysql/protocol.rb', line 358

def crypt_password(plain)
  return "" if plain.nil? or plain.empty?
  hash_stage1 = Digest::SHA1.digest plain
  hash_stage2 = Digest::SHA1.digest hash_stage1
  return hash_stage1.unpack("C*").zip(Digest::SHA1.digest(@scramble_buff+hash_stage2).unpack("C*")).map{|a,b| a^b}.pack("C*")
end