Skip to content

Commit 9568100

Browse files
committed
Fixed equality test for EC keys
1 parent 4072521 commit 9568100

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/cryptojwt/jwe/aes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def encrypt(self, msg, iv='', auth_data=None):
111111
:param msg: The message to be encrypted
112112
:param iv: MUST be present, at least 96-bit long
113113
:param auth_data: Associated data
114-
:return: The ciphertext bytes with the 16 byte tag appended.
114+
:return: The cipher text bytes with the 16 byte tag appended.
115115
"""
116116
if not iv:
117117
raise ValueError('Missing Nonce')

src/cryptojwt/jwk/ec.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ def __eq__(self, other):
278278
if cmp_keys(self.pub_key, other.pub_key, ec.EllipticCurvePublicKey):
279279
if other.private_key():
280280
if cmp_keys(self.priv_key, other.priv_key,
281-
ec.EllipticCurvePublicKey):
282-
return False
281+
ec.EllipticCurvePrivateKey):
282+
return True
283+
elif self.private_key():
284+
return False
283285
else:
284286
return True
285287

@@ -289,7 +291,7 @@ def __eq__(self, other):
289291
def cmp_keys(a, b, key_type):
290292
if isinstance(a, key_type):
291293
if isinstance(b, key_type):
292-
if a.curve != b.curve:
294+
if a.curve.name != b.curve.name:
293295
return False
294296
if a.key_size != b.key_size:
295297
return False

tests/test_02_jwk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ def test_cmp_neq_ec():
200200
assert _key1 != _key2
201201

202202

203+
def test_cmp_eq_ec():
204+
ec_key = generate_private_key(NIST2SEC['P-256'], default_backend())
205+
_key1 = ECKey(priv_key=ec_key)
206+
_key2 = ECKey(priv_key=ec_key)
207+
208+
assert _key1 == _key2
209+
210+
203211
def test_get_key():
204212
ec_key = generate_private_key(NIST2SEC['P-256'], default_backend())
205213
asym_private_key = ECKey(priv_key=ec_key)

0 commit comments

Comments
 (0)