ecordell / pymacaroons

A Python Macaroon Library
pymacaroons.readthedocs.org
MIT License
79 stars 23 forks source link

Comparing two identical deserialized macaroons doesn't seem possible? #62

Closed miketheman closed 1 year ago

miketheman commented 1 year ago

Example:

import pymacaroons

SERIALIZED_MACAROON = "MDAyMWxvY2F0aW9uIGh0dHBzOi8vZXhhbXBsZS5jb20KMDAxYmlkZW50aWZpZXIgdXNlcm5hbWUxMjMKMDAyZnNpZ25hdHVyZSB24dEoAhniYx228C6bPKNBsdHCEsIcDF9y5oQtG_Wl7wo"

deserialized1 = pymacaroons.Macaroon.deserialize(SERIALIZED_MACAROON)
deserialized2 = pymacaroons.Macaroon.deserialize(SERIALIZED_MACAROON)

assert deserialized1 == deserialized2

Returns False, and I think it should return True.

Does the Macaroon class need __eq__ implemented, or is there some other way to compare Macaroons?

ecordell commented 1 year ago

I'm not opposed to implementing __eq__, but it's simple enough to check equality via their signatures:

        assert deserialized1.signature == deserialized2.signature
miketheman commented 1 year ago

That's ... almost too simple. 🤦

Thanks for the pointer! Happy to close this, or leave it open if you want to implement __eq__ based on signature comparison, I guess?