diff --git a/jwcrypto/jwe.py b/jwcrypto/jwe.py index cbe64a1..d3a271a 100644 --- a/jwcrypto/jwe.py +++ b/jwcrypto/jwe.py @@ -525,6 +525,18 @@ def from_jose_token(cls, token): obj.deserialize(token) return obj + def __eq__(self, other): + if not isinstance(other, JWE): + return False + try: + return self.serialize() == other.serialize() + except Exception: # pylint: disable=broad-except + a = {'plaintext': self.plaintext} + a.update(self.objects) + b = {'plaintext': other.plaintext} + b.update(other.objects) + return a == b + def __str__(self): try: return self.serialize() diff --git a/jwcrypto/jws.py b/jwcrypto/jws.py index c3aba23..1e1c686 100644 --- a/jwcrypto/jws.py +++ b/jwcrypto/jws.py @@ -646,6 +646,14 @@ def from_jose_token(cls, token): obj.deserialize(token) return obj + def __eq__(self, other): + if not isinstance(other, JWS): + return False + try: + return self.serialize() == other.serialize() + except Exception: # pylint: disable=broad-except + return self.objects == other.objects + def __str__(self): try: return self.serialize() diff --git a/jwcrypto/jwt.py b/jwcrypto/jwt.py index 187e2c7..ff8c899 100644 --- a/jwcrypto/jwt.py +++ b/jwcrypto/jwt.py @@ -580,6 +580,13 @@ def from_jose_token(cls, token): obj.deserialize(token) return obj + def __eq__(self, other): + if not isinstance(other, JWT): + return False + return self._claims == other._claims and \ + self._header == other._header and \ + self.token == other.token + def __str__(self): try: return self.serialize()