@@ -101,13 +101,7 @@ def __init__(self, type: COSETypes, msg: List[Any]):
101101 def __eq__ (self : COSEMessage , other : object ) -> bool :
102102 if not isinstance (other , COSEMessage ):
103103 return NotImplemented
104- return (
105- self ._type == other ._type
106- and self ._protected == other ._protected
107- and self ._unprotected == other ._unprotected
108- and self ._payload == other ._payload
109- and self ._other_fields == other ._other_fields
110- )
104+ return self ._type == other ._type and self ._msg == other ._msg
111105
112106 def __ne__ (self : COSEMessage , other : object ) -> bool :
113107 return not self .__eq__ (other )
@@ -307,16 +301,17 @@ def detach_payload(self) -> Tuple[COSEMessage, bytes]:
307301 Detach a payload from the COSE message
308302
309303 Returns:
310- Tuple[COSEMessage, bytes]: A byte string of the encoded COSE or a
311- cbor2.CBORTag object, and a byte string of the detached payload.
304+ Tuple[COSEMessage, bytes]: The COSE message (self),
305+ and a byte string of the detached payload.
312306 Raises:
313307 ValueError: The payload does not exist.
314308 """
315309
316- if not isinstance ( self ._payload , bytes ) :
310+ if self ._msg [ 2 ] is None :
317311 raise ValueError ("The payload does not exist." )
318312
319- return COSEMessage (self ._type , [self ._msg [0 ], self ._msg [1 ], None , * self ._msg [3 :]]), self ._payload
313+ self ._msg [2 ] = None
314+ return self , self ._payload
320315
321316 def attach_payload (self , payload : bytes ) -> COSEMessage :
322317 """
@@ -330,7 +325,8 @@ def attach_payload(self, payload: bytes) -> COSEMessage:
330325 ValueError: The payload already exist.
331326 """
332327
333- if self ._payload is not None :
328+ if self ._msg [ 2 ] is not None :
334329 raise ValueError ("The payload already exist." )
330+ self ._payload = payload
335331
336- return COSEMessage ( self . _type , [ self . _msg [ 0 ], self . _msg [ 1 ], payload , * self . _msg [ 3 :]])
332+ return self
0 commit comments