mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 12:57:52 +00:00
Change the way int to bytes conversion is used
Maybe at some point I should switch to struct
This commit is contained in:
parent
07a9cce8ef
commit
4c9d9d84f2
@ -30,7 +30,7 @@ class BoolFalse(Object):
|
||||
return cls.value
|
||||
|
||||
def __new__(cls) -> bytes:
|
||||
return int.to_bytes(cls.ID, 4, "little")
|
||||
return cls.ID.to_bytes(4, "little")
|
||||
|
||||
|
||||
class BoolTrue(BoolFalse):
|
||||
|
@ -48,7 +48,7 @@ class Bytes(Object):
|
||||
else:
|
||||
return (
|
||||
bytes([254])
|
||||
+ int.to_bytes(length, 3, "little")
|
||||
+ length.to_bytes(3, "little")
|
||||
+ value
|
||||
+ bytes(-length % 4)
|
||||
)
|
||||
|
@ -29,7 +29,7 @@ class Int(Object):
|
||||
return int.from_bytes(b.read(cls.SIZE), "little", signed=signed)
|
||||
|
||||
def __new__(cls, value: int, signed: bool = True) -> bytes:
|
||||
return int.to_bytes(value, cls.SIZE, "little", signed=signed)
|
||||
return value.to_bytes(cls.SIZE, "little", signed=signed)
|
||||
|
||||
|
||||
class Long(Int):
|
||||
|
@ -29,4 +29,4 @@ class Null(Object):
|
||||
return None
|
||||
|
||||
def __new__(cls) -> bytes:
|
||||
return int.to_bytes(cls.ID, 4, "little")
|
||||
return cls.ID.to_bytes(4, "little")
|
||||
|
@ -206,12 +206,8 @@ class RSA:
|
||||
|
||||
@classmethod
|
||||
def encrypt(cls, data: bytes, fingerprint: int) -> bytes:
|
||||
return int.to_bytes(
|
||||
pow(
|
||||
int.from_bytes(data, "big"),
|
||||
cls.server_public_keys[fingerprint].e,
|
||||
cls.server_public_keys[fingerprint].m
|
||||
),
|
||||
256,
|
||||
"big"
|
||||
)
|
||||
return pow(
|
||||
int.from_bytes(data, "big"),
|
||||
cls.server_public_keys[fingerprint].e,
|
||||
cls.server_public_keys[fingerprint].m
|
||||
).to_bytes(256, "big")
|
||||
|
@ -111,8 +111,8 @@ class Auth:
|
||||
|
||||
data = types.PQInnerData(
|
||||
res_pq.pq,
|
||||
int.to_bytes(p, 4, "big"),
|
||||
int.to_bytes(q, 4, "big"),
|
||||
p.to_bytes(4, "big"),
|
||||
q.to_bytes(4, "big"),
|
||||
nonce,
|
||||
server_nonce,
|
||||
new_nonce,
|
||||
@ -131,8 +131,8 @@ class Auth:
|
||||
functions.ReqDHParams(
|
||||
nonce,
|
||||
server_nonce,
|
||||
int.to_bytes(p, 4, "big"),
|
||||
int.to_bytes(q, 4, "big"),
|
||||
p.to_bytes(4, "big"),
|
||||
q.to_bytes(4, "big"),
|
||||
public_key_fingerprint,
|
||||
encrypted_data
|
||||
)
|
||||
@ -140,8 +140,8 @@ class Auth:
|
||||
|
||||
encrypted_answer = server_dh_params.encrypted_answer
|
||||
|
||||
server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True)
|
||||
new_nonce = int.to_bytes(new_nonce, 32, "little", signed=True)
|
||||
server_nonce = server_nonce.to_bytes(16, "little", signed=True)
|
||||
new_nonce = new_nonce.to_bytes(32, "little", signed=True)
|
||||
|
||||
tmp_aes_key = (
|
||||
sha1(new_nonce + server_nonce).digest()
|
||||
@ -170,7 +170,7 @@ class Auth:
|
||||
# Step 6
|
||||
g = server_dh_inner_data.g
|
||||
b = int.from_bytes(urandom(256), "big")
|
||||
g_b = int.to_bytes(pow(g, b, dh_prime), 256, "big")
|
||||
g_b = pow(g, b, dh_prime).to_bytes(256, "big")
|
||||
|
||||
retry_id = 0
|
||||
|
||||
@ -199,8 +199,8 @@ class Auth:
|
||||
|
||||
# Step 7; Step 8
|
||||
g_a = int.from_bytes(server_dh_inner_data.g_a, "big")
|
||||
auth_key = int.to_bytes(pow(g_a, b, dh_prime), 256, "big")
|
||||
server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True)
|
||||
auth_key = pow(g_a, b, dh_prime).to_bytes(256, "big")
|
||||
server_nonce = server_nonce.to_bytes(16, "little", signed=True)
|
||||
|
||||
# TODO: Handle errors
|
||||
|
||||
@ -235,7 +235,7 @@ class Auth:
|
||||
# 3rd message
|
||||
assert nonce == set_client_dh_params_answer.nonce
|
||||
assert server_nonce == set_client_dh_params_answer.server_nonce
|
||||
server_nonce = int.to_bytes(server_nonce, 16, "little", signed=True)
|
||||
server_nonce = server_nonce.to_bytes(16, "little", signed=True)
|
||||
log.debug("Nonce fields check: OK")
|
||||
|
||||
# Step 9
|
||||
|
Loading…
x
Reference in New Issue
Block a user