private void AuthenticationChange() { MyCatPacket packet = driver.Packet; packet.Clear(); byte[] moreData = MoreData(null); while (moreData != null && moreData.Length > 0) { packet.Clear(); packet.Write(moreData); driver.SendPacket(packet); packet = ReadPacket(); byte prefixByte = packet.Buffer[0]; if (prefixByte != 1) { return; } // a prefix of 0x01 means need more auth data byte[] responseData = new byte[packet.Length - 1]; Array.Copy(packet.Buffer, 1, responseData, 0, responseData.Length); moreData = MoreData(responseData); } // we get here if MoreData returned null but the last packet read was a more data packet ReadPacket(); }
private void WritePassword(MyCatPacket packet) { bool secure = (Flags & ClientFlags.SECURE_CONNECTION) != 0; object password = GetPassword(); if (password is string) { if (secure) { packet.WriteLenString((string)password); } else { packet.WriteString((string)password); } } else if (password == null) { packet.WriteByte(0); } else if (password is byte[]) { packet.Write(password as byte[]); } else { throw new MyCatException("Unexpected password format: " + password.GetType()); } }
void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length) { double v = (val is double) ? (double)val : Convert.ToDouble(val); if (binary) { packet.Write(BitConverter.GetBytes(v)); } else { packet.WriteStringNoNull(v.ToString("R", CultureInfo.InvariantCulture)); } }
void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length) { byte[] buffToWrite = (val as byte[]); if (buffToWrite == null) { char[] valAsChar = (val as Char[]); if (valAsChar != null) { buffToWrite = packet.Encoding.GetBytes(valAsChar); } else { string s = val.ToString(); if (length == 0) { length = s.Length; } else { s = s.Substring(0, length); } buffToWrite = packet.Encoding.GetBytes(s); } } // we assume zero length means write all of the value if (length == 0) { length = buffToWrite.Length; } if (buffToWrite == null) { throw new MyCatException("Only byte arrays and strings can be serialized by MyCatBinary"); } if (binary) { packet.WriteLength(length); packet.Write(buffToWrite, 0, length); } else { packet.WriteStringNoNull("X"); packet.WriteStringNoNull("\'"); packet.WriteStringNoNull(ToHexString(buffToWrite)); packet.WriteStringNoNull("\'"); } }
private void WriteOldGuid(MyCatPacket packet, Guid guid, bool binary) { byte[] bytes = guid.ToByteArray(); if (binary) { packet.WriteLength(bytes.Length); packet.Write(bytes); } else { packet.WriteStringNoNull("_binary "); packet.WriteByte((byte)'\''); EscapeByteArray(bytes, bytes.Length, packet); packet.WriteByte((byte)'\''); } }