-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
copy.copy for private keys #11859
Comments
As I noted there, we've never intentionally supported copying keys. I'm frankly not even sure how Python's default copy implementation could work correctly. I'm a bit ambivalent about supporting copy with private keys. The same logic about them being immutable holds. Though copy may be more difficult to support for out of process keys, and we certainly don't want to preclude those. What is the actual use case here? WDYT @reaperhulk? |
The actual use case I had was to make my own |
I'm not familiar with pydantic, but it's surprising to me that it'd be invoking copy on arbitrary types. To me, that seems like the point worth investigating. |
This issue has been waiting for a reporter response for 3 days. It will be auto-closed if no activity occurs in the next 5 days. |
I agree it's weird that it does that deepcopy, but still I don't see that as a reason why cryptography shouldn't support copying the key. There's likely sooner or later some other use case for it and shouldn't be many lines of change to support it, if it's immutable. So I'd rather ask the question as why should the RSAPrivateKey not support copying? As a temporary workaround for my particular use case I implemented a |
Just as a framing matter, we tend not to ask the question "why should [type X] not support [some operation]", but rather why should it do so. This is because, all other things being equal, narrower interfaces are better: they give users clearer glide paths, and provide more flexibility for implementers down the road. But, obviously we add new APIs all the time, and we do that via a balancing test. What value is added by the new API, weighed against risks/costs. In this case, the value is that it'll let private keys be attributes in pydantic types which are copied for unspecified reasons. And the costs/risks are that we need to assess whether there are legitimate reasons that a private key implementor might not be able to provide So to do this, we need to do that homework of thinking hard about whether there's types of private keys that wouldn't be able to implement this. Once we satisfy ourselves that there's not, we could go ahead with this. I realize this seems pretty pedantic, but we try hard to avoid boxing ourselves into a corner where we'd be forced to make backwards incompatible changes in the future. (Particularly given that the reason the keys are being copied is a bit unclear and that there is a workaround.) |
Private keys (at least RSAPrivateKey) can not be copied in cryptography 43.0.3:
There was a similar issue for public keys reported in #9403 and it seems like the fix to that issue only made it possible to copy all the public keys, not any of the private ones.
The text was updated successfully, but these errors were encountered: