-
Notifications
You must be signed in to change notification settings - Fork 708
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
derive Copy and Clone for UnboundKey #1158
Conversation
0ea91e0
to
dd929e5
Compare
Looks like something like this has been discussed before in #727 and #859, but some of that discussion was before One thing @briansmith mentioned is that ring wants to abstract over keys contained in keyrings and things. In that world, presumably we'd still like to give callers the option to avoid repeating the work of AES key setup? Where in the type hierarchy would it make sense to this sort of thing? |
Codecov Report
@@ Coverage Diff @@
## main #1158 +/- ##
==========================================
- Coverage 91.97% 91.94% -0.04%
==========================================
Files 106 106
Lines 14238 14290 +52
==========================================
+ Hits 13096 13139 +43
- Misses 1142 1151 +9
Continue to review full report at Codecov.
|
OpeningKey and SealingKey intentionally avoid implementing Copy and Clone, because they're attached to a nonce sequence that should be unique. UnboundKey isn't attached to a nonce sequence, though, and in the case of AES it also takes some nontrivial key setup work to construct from raw bytes. Making it Copy and Clone allows lets callers avoid repeating that work in cases where a key is reused without a fixed nonce sequence.
dd929e5
to
0e54b85
Compare
I think it might make sense for |
Just to clarify further, If somebody thinks that we need to support cloning I'm going to close this. If I've overlooked something, please let me know. Thanks! |
Is it a downside to require heap allocation in this case? Might not be ideal for libraries planning to support |
Given that |
Cool, I just opened a separate PR for that at #1175. |
OpeningKey and SealingKey intentionally avoid implementing Copy and
Clone, because they're attached to a nonce sequence that should be
unique. UnboundKey isn't attached to a nonce sequence, though, and in
the case of AES it also takes some nontrivial key setup work to
construct from raw bytes. Making it Copy and Clone allows lets callers
avoid repeating that work in cases where a key is reused without a fixed
nonce sequence.
Copying keys around is a risky business, which is why this hierarchy of types exists in the first place, and I wouldn't be surprised if there were some objections here. Maybe some folks would prefer to implement
Clone
but notCopy
, for example. I figured it would be easier to start that conversation with some code than to just open an issue, so here's a first draft PR :)