Skip to content

Commit

Permalink
Fix _ez_unpack_auth and _ez_unpack_noauth return types
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovsky committed May 6, 2022
1 parent 1b7cce8 commit 366fd18
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ipv8/lazy_community.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod
from functools import wraps
from typing import Iterable, List, Tuple, Type, Union
from typing import Iterable, List, Tuple, Type, TypeVar, Union

from .keyvault.crypto import default_eccrypto
from .messaging.payload_headers import BinMemberAuthenticationPayload, GlobalTimeDistributionPayload
Expand Down Expand Up @@ -180,6 +180,10 @@ def inner_wrapper(inner_self, inner_source_address, *pyls):
return decorator


P = TypeVar('P', bound=AnyPayload)
PT = Type[P]


class EZPackOverlay(Overlay, ABC):

@abstractmethod
Expand Down Expand Up @@ -244,10 +248,8 @@ def _verify_signature(self, auth: BinMemberAuthenticationPayload, data: bytes) -
signature = data[-signature_length:]
return ec.is_valid_signature(public_key, data[:-signature_length], signature), remainder

def _ez_unpack_auth(self,
payload_class: AnyPayloadType,
data: bytes) -> Tuple[BinMemberAuthenticationPayload, GlobalTimeDistributionPayload,
AnyPayload]:
def _ez_unpack_auth(self, payload_class: PT, data: bytes) -> Tuple[
BinMemberAuthenticationPayload, GlobalTimeDistributionPayload, P]:
# UNPACK
auth, _ = self.serializer.unpack_serializable(BinMemberAuthenticationPayload, data, offset=23)
signature_valid, remainder = self._verify_signature(auth, data)
Expand All @@ -259,10 +261,7 @@ def _ez_unpack_auth(self,
# PRODUCE
return auth, unpacked[0], unpacked[1]

def _ez_unpack_noauth(self,
payload_class: AnyPayloadType,
data: bytes,
global_time: bool = True) -> Union[List[AnyPayload], AnyPayload]:
def _ez_unpack_noauth(self, payload_class: PT, data: bytes, global_time: bool = True) -> Union[List[AnyPayload], P]:
# UNPACK
format = [GlobalTimeDistributionPayload, payload_class] if global_time else [payload_class]
unpacked = self.serializer.unpack_serializable_list(format, data, offset=23)
Expand Down

0 comments on commit 366fd18

Please sign in to comment.