0

I've some Python pytests that call (indirectly)

key = joserfc.jwk.RSAKey.import_key(string).

This is pretty slow so I'm hoping there is a way I can save the (string,key) combination in a cache, and then use that to stub the call. I've tried saving key using pickle, but I get TypeError: cannot pickle 'cryptography.hazmat.bindings._rust.openssl.rsa.RSAPrivateKey' object

3
  • You can't use pickle, but you can use the serialization methods of the cryptography package. See cryptography.io/en/stable/hazmat/primitives/asymmetric/rsa/… and cryptography.io/en/stable/hazmat/primitives/asymmetric/rsa/…. Commented Dec 31, 2024 at 20:47
  • Thanks. I've now looked into that a bit. I can indeed get the public/private bytes from an RSAPublicKey and an RSAPrivateKey and serialize the bytes. The problem is that key (as returned from the import_key method) is neither an RSAPublicKey nor an RSAPrivateKey. So it seems I still need to call import_key (so the following statements that use key are unaffected by the stubbing). Commented Jan 1 at 11:12
  • I'll try and look at it again in more detail. Commented Jan 2 at 0:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.