From eed9fd5aec143c1ce3931858b77870a7a9367fb0 Mon Sep 17 00:00:00 2001 From: Jakob Schlyter Date: Mon, 2 Dec 2024 17:45:24 +0100 Subject: [PATCH] include use and key_ops --- jwcrypto/jwk.py | 2 +- jwcrypto/tests.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/jwcrypto/jwk.py b/jwcrypto/jwk.py index c97501c..8db4c07 100644 --- a/jwcrypto/jwk.py +++ b/jwcrypto/jwk.py @@ -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": diff --git a/jwcrypto/tests.py b/jwcrypto/tests.py index 952191c..8569e9d 100644 --- a/jwcrypto/tests.py +++ b/jwcrypto/tests.py @@ -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):