Skip to content

Commit

Permalink
include use and key_ops
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Dec 2, 2024
1 parent 3fb38f2 commit eed9fd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jwcrypto/jwk.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def generate_similar(cls, key):
return cls.generate(**key.get_generate_params())

def get_generate_params(self):
params = {param: self.get(param) for param in ["kty", "crv"] if param in self}
params = {param: self.get(param) for param in ["kty", "crv", "use", "key_ops"] if param in self}
if self.get("kty") == "RSA":
params["size"] = self._get_public_key().key_size
elif self.get("kty") == "oct":
Expand Down
16 changes: 13 additions & 3 deletions jwcrypto/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,23 @@ def test_generate_similar(self):
{
"kty": "OKP",
"crv": "X448"
}
},
{
"kty": "RSA",
"size": 3072,
"use": "sig"
},
{
"kty": "oct",
"size": 256,
"key_ops": "sign"
},
]
for params in KEY_PARAMS:
key1 = jwk.JWK.generate(**params)
key2 = jwk.JWK.generate_similar(key1)
self.assertEqual(key1.get("kty"), key2.get("kty"))
self.assertEqual(key1.get("crv"), key2.get("crv"))
for prop in ["kty", "crv", "use", "key_ops"]:
self.assertEqual(key1.get(prop), key2.get(prop))
self.assertEqual(type(key1.get_op_key("sign")), type(key2.get_op_key("sign")))

def test_jwkset(self):
Expand Down

0 comments on commit eed9fd5

Please sign in to comment.