commit before moving to ec

This commit is contained in:
JJTech0130 2023-09-17 16:55:09 -04:00
parent 33cec3cdca
commit f062542edc
No known key found for this signature in database
GPG key ID: 23C92EBCCF8F93D6
2 changed files with 39 additions and 35 deletions

28
apns.py
View file

@ -374,6 +374,18 @@ class APNSField:
self.id.to_bytes(1, "big") + len(self.value).to_bytes(2, "big") + self.value self.id.to_bytes(1, "big") + len(self.value).to_bytes(2, "big") + self.value
) )
async def receive_exact(stream: trio.abc.Stream, length: int) -> bytes:
"""Receives exactly length bytes from the given stream"""
buffer = b""
while len(buffer) < length:
b = await stream.receive_some(length - len(buffer))
if b == b"":
raise Exception("Unable to read payload from stream (EOF)")
elif b is None:
logger.warning("Got None from receive_some, why?")
else:
buffer += b
return buffer
@dataclass @dataclass
class APNSPayload: class APNSPayload:
@ -385,24 +397,16 @@ class APNSPayload:
@staticmethod @staticmethod
async def read_from_stream(stream: trio.abc.Stream) -> APNSPayload: async def read_from_stream(stream: trio.abc.Stream) -> APNSPayload:
"""Reads a payload from the given stream""" """Reads a payload from the given stream"""
if not (id_bytes := await stream.receive_some(1)): id = await receive_exact(stream, 1)
raise Exception("Unable to read payload id from stream") id = int.from_bytes(id, "big")
id: int = int.from_bytes(id_bytes, "big")
if (length := await stream.receive_some(4)) is None: length = await receive_exact(stream, 4)
raise Exception("Unable to read payload length from stream")
length = int.from_bytes(length, "big") length = int.from_bytes(length, "big")
if length == 0: if length == 0:
return APNSPayload(id, []) return APNSPayload(id, [])
# Make sure we receive length bytes buffer = await receive_exact(stream, length)
buffer = b""
while len(buffer) < length:
b = await stream.receive_some(length - len(buffer))
if b == b"":
raise Exception("Unable to read payload from stream (EOF)")
buffer += b
fields = [] fields = []

View file

@ -174,30 +174,30 @@ def register(
"sub-services": [], "sub-services": [],
"users": [ "users": [
{ {
# "client-data": {
# "public-message-identity-key": identity.encode(),
# "public-message-identity-version": 2,
# "supports-avless": True,
# "supports-co": True,
# "supports-gft-calls": True,
# "supports-gft-errors": True,
# "supports-modern-gft": True,
# "supports-self-one-to-one-invites": True,
# },
"client-data": { "client-data": {
"public-message-ngm-device-prekey-data-key": b"\n \xb4\\\x15\x8e\xa4\xc8\xe5\x07\x98\tp\xd0\xa4^\x84k\x05#Ep\xa9*\xcd\xadt\xf5\xb0\xfb\xa6_ho\x12@\xe3\xf5\xcaOwh\xfd\xb9\xecD\t\x0e\x9e\xb8\xb0\xa1\x1c=\x92\x9dD/lmL\xde.\\o\xeb\x15>\x9f\xae\xd9\xf9\xd1\x9c*\x8dU\xe0\xd2\xdeo\xb2\xcb\xd8\xf8i\xd4\xd0a^\t!\x0fa\xb2\xddI\xfc_*\x19\xb2\xf0#\x12\xe0@\xd9A", "public-message-identity-key": identity.encode(),
"supports-avless": True, "public-message-identity-version": 2,
"public-message-identity-key": b"0\x81\xf6\x81C\x00A\x04\x87\x1e\xeb\xe4u\x0b\xa3\x9e\x9c\xbc\xf8rK\x1e\xfe44%f$\x1d\xe8\xbb\xc6\xbdCD\x9ckv K\xc1\x1e\xb1\xdf4\xc8S6\x0f\x92\xd0=\x1e\x84\x9c\xc5\xa5\xb6\xb7}\xdd\xec\x1e\x1e\xd8Q\xd8\xca\xdb\x07'\xc7\x82\x81\xae\x00\xac0\x81\xa9\x02\x81\xa1\x00\xa8 \xfc\x9f\xa6\xb0V2\xce\x1c\xa7\x13\x9e\x03\xd1\xd8\x97a\xbb\xdd\xac\x86\xb8\x10(\x89\x13QP\x8f\xf0+EP\xd1\xb06\xee\x94\xcd\xa8\x9e\xf1\xedp\xa4\x9726\x1e\xe9\xab\xd4\xcb\xac\x05\xd7\x8c?\xbb\xa2\xde,\xfe\r\x1a\xb9\x88W@\x99\xec\xa0]\r\x1a>dV\xb2@\xc5P\xf3m\x80y\xf5\xa0G\xae\xd8h\x92\xef\xca\x85\xcbB\xed\xa9W\x8c\x13\xd4O\xdbYI2\xdcM\x1f\xf6c\x17\x1c\xd1v\xdd\xbcc\xac,&V\xfd\x07\xa0\xc3\x9f\x00\x1f\xc6\xe4\x02u\x12p\x8f\xe2\xb0\x14\xfai\x12\xbb\xa6\x9a6Q\xa5\xde+\x9e{\xcf\xc8\x1b}\x02\x03\x01\x00\x01", "supports-avless": True,
"supports-gft-calls": True, "supports-co": True,
"public-message-identity-version": 2.0, "supports-gft-calls": True,
"supports-co": True, "supports-gft-errors": True,
"supports-gft-errors": True, "supports-modern-gft": True,
"supports-self-one-to-one-invites": True, "supports-self-one-to-one-invites": True,
"supports-modern-gft": True, },
"public-message-identity-ngm-version": 12.0, # "client-data": {
"device-key-signature": b"0a\x04\x14\x1d\xb02~\xefk&\xf8\r;R\xa4\x95c~\x8a\x90H\x85\xb0\x02\x01\x01\x04F0D\x02 @\xce\xa7P6\x89\x92Wf\x87\xc9\xc5M-\xb1\xe5Q\x9f\x7fKi\x1bp\xd5\x12\x1c,:\xdb\xed\x08\x12\x02 l\xfd\\\xe2\xd3:,\xc1\xd8\x08|\xbe\x05M\x12\xee@\xc2=eR8:\xa7h3u|\x83ia\x19", # "public-message-ngm-device-prekey-data-key": b"\n \xb4\\\x15\x8e\xa4\xc8\xe5\x07\x98\tp\xd0\xa4^\x84k\x05#Ep\xa9*\xcd\xadt\xf5\xb0\xfb\xa6_ho\x12@\xe3\xf5\xcaOwh\xfd\xb9\xecD\t\x0e\x9e\xb8\xb0\xa1\x1c=\x92\x9dD/lmL\xde.\\o\xeb\x15>\x9f\xae\xd9\xf9\xd1\x9c*\x8dU\xe0\xd2\xdeo\xb2\xcb\xd8\xf8i\xd4\xd0a^\t!\x0fa\xb2\xddI\xfc_*\x19\xb2\xf0#\x12\xe0@\xd9A",
}, # "supports-avless": True,
"kt-loggable-data": b'\n"\n \rl\xbe\xca\xf7\xe8\xb2\x89k\x18\x1e\xb9,d\xf8\xe2\n\xbf\x8d\xe1E\xd6\xf3T\xcb\xd9\x99d\xd1mk\xeb\x10\x0c\x18\x05', # "public-message-identity-key": b"0\x81\xf6\x81C\x00A\x04\x87\x1e\xeb\xe4u\x0b\xa3\x9e\x9c\xbc\xf8rK\x1e\xfe44%f$\x1d\xe8\xbb\xc6\xbdCD\x9ckv K\xc1\x1e\xb1\xdf4\xc8S6\x0f\x92\xd0=\x1e\x84\x9c\xc5\xa5\xb6\xb7}\xdd\xec\x1e\x1e\xd8Q\xd8\xca\xdb\x07'\xc7\x82\x81\xae\x00\xac0\x81\xa9\x02\x81\xa1\x00\xa8 \xfc\x9f\xa6\xb0V2\xce\x1c\xa7\x13\x9e\x03\xd1\xd8\x97a\xbb\xdd\xac\x86\xb8\x10(\x89\x13QP\x8f\xf0+EP\xd1\xb06\xee\x94\xcd\xa8\x9e\xf1\xedp\xa4\x9726\x1e\xe9\xab\xd4\xcb\xac\x05\xd7\x8c?\xbb\xa2\xde,\xfe\r\x1a\xb9\x88W@\x99\xec\xa0]\r\x1a>dV\xb2@\xc5P\xf3m\x80y\xf5\xa0G\xae\xd8h\x92\xef\xca\x85\xcbB\xed\xa9W\x8c\x13\xd4O\xdbYI2\xdcM\x1f\xf6c\x17\x1c\xd1v\xdd\xbcc\xac,&V\xfd\x07\xa0\xc3\x9f\x00\x1f\xc6\xe4\x02u\x12p\x8f\xe2\xb0\x14\xfai\x12\xbb\xa6\x9a6Q\xa5\xde+\x9e{\xcf\xc8\x1b}\x02\x03\x01\x00\x01",
# "supports-gft-calls": True,
# "public-message-identity-version": 2.0,
# "supports-co": True,
# "supports-gft-errors": True,
# "supports-self-one-to-one-invites": True,
# "supports-modern-gft": True,
# "public-message-identity-ngm-version": 12.0,
# "device-key-signature": b"0a\x04\x14\x1d\xb02~\xefk&\xf8\r;R\xa4\x95c~\x8a\x90H\x85\xb0\x02\x01\x01\x04F0D\x02 @\xce\xa7P6\x89\x92Wf\x87\xc9\xc5M-\xb1\xe5Q\x9f\x7fKi\x1bp\xd5\x12\x1c,:\xdb\xed\x08\x12\x02 l\xfd\\\xe2\xd3:,\xc1\xd8\x08|\xbe\x05M\x12\xee@\xc2=eR8:\xa7h3u|\x83ia\x19",
# },
# "kt-loggable-data": b'\n"\n \rl\xbe\xca\xf7\xe8\xb2\x89k\x18\x1e\xb9,d\xf8\xe2\n\xbf\x8d\xe1E\xd6\xf3T\xcb\xd9\x99d\xd1mk\xeb\x10\x0c\x18\x05',
"uris": uris, "uris": uris,
"user-id": user_id, "user-id": user_id,