1+ from __future__ import annotations
2+
13from typing import Any , Dict , List , Optional , Tuple , TypeVar
24
35from cbor2 import CBORTag , loads
@@ -98,7 +100,9 @@ def __init__(self, type: COSETypes, msg: List[Any]):
98100 raise ValueError (f"Invalid COSETypes({ type } ) for COSE message." )
99101 return
100102
101- def __eq__ (self : Self , other : Self ) -> bool :
103+ def __eq__ (self : COSEMessage , other : object ) -> bool :
104+ if not isinstance (other , COSEMessage ):
105+ return NotImplemented
102106 return (
103107 self ._type == other ._type
104108 and self ._protected == other ._protected
@@ -107,7 +111,7 @@ def __eq__(self: Self, other: Self) -> bool:
107111 and self ._other_fields == other ._other_fields
108112 )
109113
110- def __ne__ (self : Self , other : Self ) -> bool :
114+ def __ne__ (self : COSEMessage , other : object ) -> bool :
111115 return not self .__eq__ (other )
112116
113117 @classmethod
@@ -300,7 +304,7 @@ def _get_kid(self, sig: list) -> Optional[bytes]:
300304 kid = sig [1 ].get (4 , None )
301305 return kid if kid else self ._loads (sig [0 ]).get (4 , None )
302306
303- def detach_payload (self : Self ) -> Tuple [Self , bytes ]:
307+ def detach_payload (self : Self ) -> Tuple [COSEMessage , bytes ]:
304308 """
305309 Detach a payload from the COSE message
306310
@@ -316,7 +320,7 @@ def detach_payload(self: Self) -> Tuple[Self, bytes]:
316320
317321 return COSEMessage (self ._type , [self ._msg [0 ], self ._msg [1 ], None , * self ._msg [3 :]]), self ._payload
318322
319- def attach_payload (self : Self , payload : bytes ) -> Self :
323+ def attach_payload (self : Self , payload : bytes ) -> COSEMessage :
320324 """
321325 Attach a detached content to the COSE message
322326
0 commit comments