Skip to content

Commit

Permalink
Merge pull request #490 from anarkiwi/pyfix
Browse files Browse the repository at this point in the history
make pack signature consistent.
  • Loading branch information
gizmoguy authored Nov 17, 2023
2 parents d3c5e3a + bff792e commit f43bab5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions chewie/eap.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def parse(cls, code, packet_id, packed_message):
) from exception
return cls(code, packet_id, identity)

def pack(self):
def pack(self, packed_body=b''):
packed_identity = self.identity.encode()
return super().pack(packed_identity)
return super().pack(packed_identity) + packed_body

def __repr__(self):
return "%s(identity=%s)" % (self.__class__.__name__, self.identity)
Expand Down Expand Up @@ -161,10 +161,10 @@ def parse(cls, code, packet_id, packed_message):
extra_data = packed_message[1 + value_length :]
return cls(code, packet_id, challenge, extra_data)

def pack(self):
def pack(self, packed_body=b''):
value_length = struct.pack("!B", len(self.challenge))
packed_md5_challenge = value_length + self.challenge + self.extra_data
return super().pack(packed_md5_challenge)
return super().pack(packed_md5_challenge) + packed_body

def __repr__(self):
return "%s(challenge=%s, extra_data=%s)" % (
Expand All @@ -184,8 +184,8 @@ def __init__(self, packet_id):
def parse(cls, packet_id):
return cls(packet_id)

def pack(self):
return struct.pack("!BBH", Eap.SUCCESS, self.packet_id, EAP_HEADER_LENGTH)
def pack(self, packed_body=b''):
return struct.pack("!BBH", Eap.SUCCESS, self.packet_id, EAP_HEADER_LENGTH) + packed_body

def __repr__(self):
return "%s(packet_id=%s)" % (self.__class__.__name__, self.packet_id)
Expand All @@ -201,8 +201,8 @@ def __init__(self, packet_id):
def parse(cls, packet_id):
return cls(packet_id)

def pack(self):
return struct.pack("!BBH", Eap.FAILURE, self.packet_id, EAP_HEADER_LENGTH)
def pack(self, packed_body=b''):
return struct.pack("!BBH", Eap.FAILURE, self.packet_id, EAP_HEADER_LENGTH) + packed_body

def __repr__(self):
return "%s(packet_id=%s)" % (self.__class__.__name__, self.packet_id)
Expand Down Expand Up @@ -236,11 +236,11 @@ def parse(cls, code, packet_id, packed_msg):
) from exception
return cls(code, packet_id, desired_auth_types)

def pack(self):
def pack(self, packed_body=b''):
packed_legacy_nak = struct.pack(
"!%ds" % len(self.desired_auth_types), *self.desired_auth_types
) # pytype: disable=wrong-arg-types
return super().pack(packed_legacy_nak)
return super().pack(packed_legacy_nak) + packed_body

def __repr__(self):
return "%s(packet_id=%s, desired_auth_types=%s)" % (
Expand Down Expand Up @@ -283,14 +283,14 @@ def parse(cls, code, packet_id, packed_msg):

return cls(code, packet_id, flags, extra_data)

def pack(self):
def pack(self, packed_body=b''):
if self.extra_data:
packed = struct.pack(
"!B%ds" % len(self.extra_data), self.flags, self.extra_data
)
else:
packed = struct.pack("!B", self.flags)
return super().pack(packed)
return super().pack(packed) + packed_body

def __repr__(self):
return "%s(packet_id=%s, flags=%s, extra_data=%s)" % (
Expand Down
2 changes: 1 addition & 1 deletion codecheck-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pylint==3.0.2
pytype==2023.9.27
pytype==2023.10.31

0 comments on commit f43bab5

Please sign in to comment.