mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Reformat MTProto.Serializers
Fix naming for string serializer Fix naming for bytes serializer Remove unused method - VectorToString
This commit is contained in:
parent
dc8c20df63
commit
79cf25d257
|
|
@ -65,7 +65,7 @@ namespace TLSharp.Core.Auth
|
||||||
|
|
||||||
var serverNonce = binaryReader.ReadBytes(16);
|
var serverNonce = binaryReader.ReadBytes(16);
|
||||||
|
|
||||||
byte[] pqbytes = Serializers.Bytes.read(binaryReader);
|
byte[] pqbytes = Serializers.Bytes.Read(binaryReader);
|
||||||
var pq = new BigInteger(1, pqbytes);
|
var pq = new BigInteger(1, pqbytes);
|
||||||
|
|
||||||
var vectorId = binaryReader.ReadInt32();
|
var vectorId = binaryReader.ReadInt32();
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@ namespace TLSharp.Core.Auth
|
||||||
using (BinaryWriter pqInnerDataWriter = new BinaryWriter(pqInnerData))
|
using (BinaryWriter pqInnerDataWriter = new BinaryWriter(pqInnerData))
|
||||||
{
|
{
|
||||||
pqInnerDataWriter.Write(0x83c95aec); // pq_inner_data
|
pqInnerDataWriter.Write(0x83c95aec); // pq_inner_data
|
||||||
Serializers.Bytes.write(pqInnerDataWriter, pq.ToByteArrayUnsigned());
|
Serializers.Bytes.Write(pqInnerDataWriter, pq.ToByteArrayUnsigned());
|
||||||
Serializers.Bytes.write(pqInnerDataWriter, pqPair.Min.ToByteArrayUnsigned());
|
Serializers.Bytes.Write(pqInnerDataWriter, pqPair.Min.ToByteArrayUnsigned());
|
||||||
Serializers.Bytes.write(pqInnerDataWriter, pqPair.Max.ToByteArrayUnsigned());
|
Serializers.Bytes.Write(pqInnerDataWriter, pqPair.Max.ToByteArrayUnsigned());
|
||||||
pqInnerDataWriter.Write(nonce);
|
pqInnerDataWriter.Write(nonce);
|
||||||
pqInnerDataWriter.Write(serverNonce);
|
pqInnerDataWriter.Write(serverNonce);
|
||||||
pqInnerDataWriter.Write(newNonce);
|
pqInnerDataWriter.Write(newNonce);
|
||||||
|
|
@ -69,10 +69,10 @@ namespace TLSharp.Core.Auth
|
||||||
reqDHParamsWriter.Write(0xd712e4be); // req_dh_params
|
reqDHParamsWriter.Write(0xd712e4be); // req_dh_params
|
||||||
reqDHParamsWriter.Write(nonce);
|
reqDHParamsWriter.Write(nonce);
|
||||||
reqDHParamsWriter.Write(serverNonce);
|
reqDHParamsWriter.Write(serverNonce);
|
||||||
Serializers.Bytes.write(reqDHParamsWriter, pqPair.Min.ToByteArrayUnsigned());
|
Serializers.Bytes.Write(reqDHParamsWriter, pqPair.Min.ToByteArrayUnsigned());
|
||||||
Serializers.Bytes.write(reqDHParamsWriter, pqPair.Max.ToByteArrayUnsigned());
|
Serializers.Bytes.Write(reqDHParamsWriter, pqPair.Max.ToByteArrayUnsigned());
|
||||||
reqDHParamsWriter.Write(targetFingerprint);
|
reqDHParamsWriter.Write(targetFingerprint);
|
||||||
Serializers.Bytes.write(reqDHParamsWriter, ciphertext);
|
Serializers.Bytes.Write(reqDHParamsWriter, ciphertext);
|
||||||
|
|
||||||
reqDhParamsBytes = reqDHParams.ToArray();
|
reqDhParamsBytes = reqDHParams.ToArray();
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +126,7 @@ namespace TLSharp.Core.Auth
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
encryptedAnswer = Serializers.Bytes.read(responseReader);
|
encryptedAnswer = Serializers.Bytes.Read(responseReader);
|
||||||
|
|
||||||
return new Step2_Response()
|
return new Step2_Response()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,8 @@ namespace TLSharp.Core.Auth
|
||||||
// logger.debug("valid server nonce");
|
// logger.debug("valid server nonce");
|
||||||
|
|
||||||
g = dhInnerDataReader.ReadInt32();
|
g = dhInnerDataReader.ReadInt32();
|
||||||
dhPrime = new BigInteger(1, Serializers.Bytes.read(dhInnerDataReader));
|
dhPrime = new BigInteger(1, Serializers.Bytes.Read(dhInnerDataReader));
|
||||||
ga = new BigInteger(1, Serializers.Bytes.read(dhInnerDataReader));
|
ga = new BigInteger(1, Serializers.Bytes.Read(dhInnerDataReader));
|
||||||
|
|
||||||
int serverTime = dhInnerDataReader.ReadInt32();
|
int serverTime = dhInnerDataReader.ReadInt32();
|
||||||
timeOffset = serverTime - (int)(Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds) / 1000);
|
timeOffset = serverTime - (int)(Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds) / 1000);
|
||||||
|
|
@ -88,7 +88,7 @@ namespace TLSharp.Core.Auth
|
||||||
clientDhInnerDataWriter.Write(nonce);
|
clientDhInnerDataWriter.Write(nonce);
|
||||||
clientDhInnerDataWriter.Write(serverNonce);
|
clientDhInnerDataWriter.Write(serverNonce);
|
||||||
clientDhInnerDataWriter.Write((long)0); // TODO: retry_id
|
clientDhInnerDataWriter.Write((long)0); // TODO: retry_id
|
||||||
Serializers.Bytes.write(clientDhInnerDataWriter, gb.ToByteArrayUnsigned());
|
Serializers.Bytes.Write(clientDhInnerDataWriter, gb.ToByteArrayUnsigned());
|
||||||
|
|
||||||
using (MemoryStream clientDhInnerDataWithHash = new MemoryStream())
|
using (MemoryStream clientDhInnerDataWithHash = new MemoryStream())
|
||||||
{
|
{
|
||||||
|
|
@ -121,7 +121,7 @@ namespace TLSharp.Core.Auth
|
||||||
setClientDhParamsWriter.Write(0xf5045f1f);
|
setClientDhParamsWriter.Write(0xf5045f1f);
|
||||||
setClientDhParamsWriter.Write(nonce);
|
setClientDhParamsWriter.Write(nonce);
|
||||||
setClientDhParamsWriter.Write(serverNonce);
|
setClientDhParamsWriter.Write(serverNonce);
|
||||||
Serializers.Bytes.write(setClientDhParamsWriter, clientDhInnerDataEncryptedBytes);
|
Serializers.Bytes.Write(setClientDhParamsWriter, clientDhInnerDataEncryptedBytes);
|
||||||
|
|
||||||
setclientDhParamsBytes = setClientDhParams.ToArray();
|
setclientDhParamsBytes = setClientDhParams.ToArray();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace TLSharp.Core.MTProto
|
||||||
|
|
||||||
public static class Bytes
|
public static class Bytes
|
||||||
{
|
{
|
||||||
public static byte[] read(BinaryReader binaryReader)
|
public static byte[] Read(BinaryReader binaryReader)
|
||||||
{
|
{
|
||||||
byte firstByte = binaryReader.ReadByte();
|
byte firstByte = binaryReader.ReadByte();
|
||||||
int len, padding;
|
int len, padding;
|
||||||
|
|
@ -33,7 +33,7 @@ namespace TLSharp.Core.MTProto
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BinaryWriter write(BinaryWriter binaryWriter, byte[] data)
|
public static BinaryWriter Write(BinaryWriter binaryWriter, byte[] data)
|
||||||
{
|
{
|
||||||
int padding;
|
int padding;
|
||||||
if (data.Length < 254)
|
if (data.Length < 254)
|
||||||
|
|
@ -73,26 +73,16 @@ namespace TLSharp.Core.MTProto
|
||||||
|
|
||||||
public static class String
|
public static class String
|
||||||
{
|
{
|
||||||
public static string read(BinaryReader reader)
|
public static string Read(BinaryReader reader)
|
||||||
{
|
{
|
||||||
byte[] data = Bytes.read(reader);
|
byte[] data = Bytes.Read(reader);
|
||||||
return Encoding.UTF8.GetString(data, 0, data.Length);
|
return Encoding.UTF8.GetString(data, 0, data.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BinaryWriter write(BinaryWriter writer, string str)
|
public static BinaryWriter Write(BinaryWriter writer, string str)
|
||||||
{
|
{
|
||||||
return Bytes.write(writer, Encoding.UTF8.GetBytes(str));
|
return Bytes.Write(writer, Encoding.UTF8.GetBytes(str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string VectorToString<T>(List<T> list)
|
|
||||||
{
|
|
||||||
string[] tokens = new string[list.Count];
|
|
||||||
for (int i = 0; i < list.Count; i++)
|
|
||||||
{
|
|
||||||
tokens[i] = list[i].ToString();
|
|
||||||
}
|
|
||||||
return "[" + System.String.Join(", ", tokens) + "]";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ namespace TLSharp.Core.Network
|
||||||
private bool HandleGzipPacked(ulong messageId, int sequence, BinaryReader messageReader, TeleSharp.TL.TLMethod request)
|
private bool HandleGzipPacked(ulong messageId, int sequence, BinaryReader messageReader, TeleSharp.TL.TLMethod request)
|
||||||
{
|
{
|
||||||
uint code = messageReader.ReadUInt32();
|
uint code = messageReader.ReadUInt32();
|
||||||
byte[] packedData = GZipStream.UncompressBuffer(Serializers.Bytes.read(messageReader));
|
byte[] packedData = GZipStream.UncompressBuffer(Serializers.Bytes.Read(messageReader));
|
||||||
using (MemoryStream packedStream = new MemoryStream(packedData, false))
|
using (MemoryStream packedStream = new MemoryStream(packedData, false))
|
||||||
using (BinaryReader compressedReader = new BinaryReader(packedStream))
|
using (BinaryReader compressedReader = new BinaryReader(packedStream))
|
||||||
{
|
{
|
||||||
|
|
@ -276,7 +276,7 @@ namespace TLSharp.Core.Network
|
||||||
if (innerCode == 0x2144ca19)
|
if (innerCode == 0x2144ca19)
|
||||||
{ // rpc_error
|
{ // rpc_error
|
||||||
int errorCode = messageReader.ReadInt32();
|
int errorCode = messageReader.ReadInt32();
|
||||||
string errorMessage = Serializers.String.read(messageReader);
|
string errorMessage = Serializers.String.Read(messageReader);
|
||||||
|
|
||||||
if (errorMessage.StartsWith("FLOOD_WAIT_"))
|
if (errorMessage.StartsWith("FLOOD_WAIT_"))
|
||||||
{
|
{
|
||||||
|
|
@ -327,7 +327,7 @@ namespace TLSharp.Core.Network
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// gzip_packed
|
// gzip_packed
|
||||||
byte[] packedData = Serializers.Bytes.read(messageReader);
|
byte[] packedData = Serializers.Bytes.Read(messageReader);
|
||||||
using (var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
using (var packedStream = new MemoryStream(packedData, false))
|
using (var packedStream = new MemoryStream(packedData, false))
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ namespace TLSharp.Core
|
||||||
writer.Write(Salt);
|
writer.Write(Salt);
|
||||||
writer.Write(LastMessageId);
|
writer.Write(LastMessageId);
|
||||||
writer.Write(TimeOffset);
|
writer.Write(TimeOffset);
|
||||||
Serializers.String.write(writer, DataCenter.Address);
|
Serializers.String.Write(writer, DataCenter.Address);
|
||||||
writer.Write(DataCenter.Port);
|
writer.Write(DataCenter.Port);
|
||||||
|
|
||||||
if (TLUser != null)
|
if (TLUser != null)
|
||||||
|
|
@ -120,7 +120,7 @@ namespace TLSharp.Core
|
||||||
writer.Write(0);
|
writer.Write(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serializers.Bytes.write(writer, AuthKey.Data);
|
Serializers.Bytes.Write(writer, AuthKey.Data);
|
||||||
|
|
||||||
return stream.ToArray();
|
return stream.ToArray();
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +136,7 @@ namespace TLSharp.Core
|
||||||
var salt = reader.ReadUInt64();
|
var salt = reader.ReadUInt64();
|
||||||
var lastMessageId = reader.ReadInt64();
|
var lastMessageId = reader.ReadInt64();
|
||||||
var timeOffset = reader.ReadInt32();
|
var timeOffset = reader.ReadInt32();
|
||||||
var serverAddress = Serializers.String.read(reader);
|
var serverAddress = Serializers.String.Read(reader);
|
||||||
var port = reader.ReadInt32();
|
var port = reader.ReadInt32();
|
||||||
|
|
||||||
var isAuthExsist = reader.ReadInt32() == 1;
|
var isAuthExsist = reader.ReadInt32() == 1;
|
||||||
|
|
@ -148,7 +148,7 @@ namespace TLSharp.Core
|
||||||
TLUser = (TLUser)ObjectUtils.DeserializeObject(reader);
|
TLUser = (TLUser)ObjectUtils.DeserializeObject(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
var authData = Serializers.Bytes.read(reader);
|
var authData = Serializers.Bytes.Read(reader);
|
||||||
var defaultDataCenter = new DataCenter (serverAddress, port);
|
var defaultDataCenter = new DataCenter (serverAddress, port);
|
||||||
|
|
||||||
return new Session(store)
|
return new Session(store)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue