-
Notifications
You must be signed in to change notification settings - Fork 129
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
Implement ZeroizeOnDrop
#699
Conversation
@@ -22,7 +22,7 @@ decl_derive!( | |||
/// Supports the following attributes: | |||
/// | |||
/// On the item level: | |||
/// - `#[zeroize(drop)]`: call `zeroize()` when this item is dropped | |||
/// - `#[zeroize(drop)]`: *deprecated* use `ZeroizeOnDrop` instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To properly deprecate this I think it'd be good to emit a #[deprecated(...)]
attribute in the generated code, although I'm fine with addressing that in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am looking into it.
zeroize/derive/src/lib.rs
Outdated
} | ||
} | ||
|
||
fn derive_zeroize_on_drop(s: &synstructure::Structure<'_>) -> TokenStream { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah okay, so derive_zeroize_on_drop
does exist, but only adds the marker trait.
I think it would make more sense to also derive the Drop
impl here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't be done that way because the method body is completely different. I could switch up the function names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching the names sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching the names was quiet confusing, I changed it up a little, how does it look to you now?
6ca6772
to
9d8d620
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine to me now.
If you'd like to add the #[deprecated]
attribute in this PR go ahead, or otherwise I can just merge.
Just checked it out, I can't get a warning to actually show up, feel free to merge, this can be done in a separate PR anyway. Do you know how this is done by any chance? I just emitted |
So https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute says:
This is the related issue: rust-lang/rust#39935. |
Yeah, you'd need to make some sort of pseudo-function (possibly in the zeroize crate) and call it from the deprecated impls. Probably best to save something that convoluted for a follow-up PR. |
Thank you! |
As discussed in #652.