Skip to content

Commit

Permalink
key usage comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
msetina committed Apr 11, 2024
1 parent 0e3808d commit c6518bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 5 additions & 7 deletions cryptography_keys_tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ def test_rsa_key_creation(self):
)
assert rsa_priv_key is not None
assert rsa_priv_key.key_size == 2048
# ku = rsa_priv_key.read_key_usage()
# for ka, val in settings["key_usage"].items():
# assert ku[ka] == val
ku = rsa_priv_key.read_key_usage()
r = current_admin.delete_key_pair()
assert ku == keydef
assert r

def test_ec_key_creation(self):
Expand All @@ -67,12 +66,11 @@ def test_ec_key_creation(self):
ec_priv_key = current_admin.create_key_pair(
keydef, key_type=KeyTypes.EC, EC_curve=SECP384R1()
)
assert ec_priv_key is not None
assert ec_priv_key.curve.__class__ is SECP384R1
# ku = ec_priv_key.read_key_usage()
# for ka, val in settings["key_usage"].items():
# assert ku[ka] == val
ku = ec_priv_key.read_key_usage()
r = current_admin.delete_key_pair()
assert ec_priv_key is not None
assert ku == keydef
assert r

def test_rsa_encryption_PKCS1v15(self):
Expand Down
12 changes: 12 additions & 0 deletions pkcs11_cryptography_keys/card_token/PKCS11_key_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ def __init__(
def get(self, key: str) -> bool | None:
return self._usage.get(key, False)

def __eq__(self, value: object) -> bool:
ret = False
if isinstance(value, PKCS11KeyUsage):
ret = True
for k, v in value._usage.items():
if k in self._usage:
if v != self._usage[k]:
ret = False
else:
ret = False
return ret


class PKCS11KeyUsageAll(PKCS11KeyUsage):
def __init__(self) -> None:
Expand Down

0 comments on commit c6518bf

Please sign in to comment.