Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix detach&attach not to create new COSEMessage instance #447

Merged
merged 9 commits into from Oct 17, 2023
12 changes: 8 additions & 4 deletions cwt/cose_message.py
Expand Up @@ -309,16 +309,19 @@ def detach_payload(self: Self) -> Tuple[COSEMessage, bytes]:
Detach a payload from the COSE message

Returns:
Tuple[COSEMessage, bytes]: A byte string of the encoded COSE or a
cbor2.CBORTag object, and a byte string of the detached payload.
Tuple[COSEMessage, bytes]: The COSE message (self),
and a byte string of the detached payload.
Raises:
ValueError: The payload does not exist.
"""

if not isinstance(self._payload, bytes):
kentakayama marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError("The payload does not exist.")

return COSEMessage(self._type, [self._msg[0], self._msg[1], None, *self._msg[3:]]), self._payload
payload = self._payload
self._payload = None

return self, payload
kentakayama marked this conversation as resolved.
Show resolved Hide resolved

def attach_payload(self: Self, payload: bytes) -> COSEMessage:
"""
Expand All @@ -334,5 +337,6 @@ def attach_payload(self: Self, payload: bytes) -> COSEMessage:

if self._payload is not None:
kentakayama marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError("The payload already exist.")
self._payload = payload

return COSEMessage(self._type, [self._msg[0], self._msg[1], payload, *self._msg[3:]])
return self