MySQLPacketHandshakeResponse41.createWithNativePassword constructor

MySQLPacketHandshakeResponse41.createWithNativePassword({
  1. required String username,
  2. required String password,
  3. required MySQLPacketInitialHandshake initialHandshakePayload,
})

Implementation

factory MySQLPacketHandshakeResponse41.createWithNativePassword({
  required String username,
  required String password,
  required MySQLPacketInitialHandshake initialHandshakePayload,
}) {
  assert(initialHandshakePayload.authPluginDataPart2 != null);
  assert(initialHandshakePayload.authPluginName != null);

  final challenge = initialHandshakePayload.authPluginDataPart1 +
      initialHandshakePayload.authPluginDataPart2!.sublist(0, 12);

  assert(challenge.length == 20);

  final passwordBytes = utf8.encode(password);

  final authData = xor(
    sha1(passwordBytes),
    sha1(challenge + sha1(sha1(passwordBytes))),
  );

  return MySQLPacketHandshakeResponse41(
    capabilityFlags: _supportedCapabitilies,
    maxPacketSize: 50 * 1024 * 1024,
    authPluginName: initialHandshakePayload.authPluginName!,
    characterSet: initialHandshakePayload.charset,
    authResponse: authData,
    username: username,
  );
}