Skip to content

Fix EC key compare (and test RSA eq) #187

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cryptojwt/jwk/ec.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@
if self.__class__ != other.__class__:
return False

if self.use and other.use:
if self.use != other.use:
return False

Check warning on line 248 in src/cryptojwt/jwk/ec.py

View check run for this annotation

Codecov / codecov/patch

src/cryptojwt/jwk/ec.py#L248

Added line #L248 was not covered by tests

if self.kid:
if other.kid:
if self.kid != other.kid:
return False
else:
return False

Check warning on line 255 in src/cryptojwt/jwk/ec.py

View check run for this annotation

Codecov / codecov/patch

src/cryptojwt/jwk/ec.py#L255

Added line #L255 was not covered by tests
else:
if other.kid:
return False

Check warning on line 258 in src/cryptojwt/jwk/ec.py

View check run for this annotation

Codecov / codecov/patch

src/cryptojwt/jwk/ec.py#L258

Added line #L258 was not covered by tests

if cmp_keys(self.pub_key, other.pub_key, ec.EllipticCurvePublicKey):
if other.private_key():
if cmp_keys(self.priv_key, other.priv_key, ec.EllipticCurvePrivateKey):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_02_jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ def test_cmp_eq_ec():
assert _key1 == _key2


def test_cmp_eq_ec_kid():
ec_key = new_ec_key("P-256")
_key1 = ECKey(priv_key=ec_key.priv_key, kid="foo")
_key2 = ECKey(priv_key=ec_key.priv_key, kid="bar")

assert _key1 != _key2


def test_cmp_eq_rsa_kid():
rsa_key = new_rsa_key()
_key1 = RSAKey(priv_key=rsa_key.priv_key, kid="foo")
_key2 = RSAKey(priv_key=rsa_key.priv_key, kid="bar")

assert _key1 != _key2


def test_get_key():
ec_key = new_ec_key("P-256")
asym_private_key = ECKey(priv_key=ec_key.priv_key)
Expand Down