Skip to content
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

ZeroizeOnDrop usage #785

Closed
fjarri opened this issue Aug 1, 2022 · 3 comments
Closed

ZeroizeOnDrop usage #785

fjarri opened this issue Aug 1, 2022 · 3 comments

Comments

@fjarri
Copy link

fjarri commented Aug 1, 2022

Returning to the question raised in iqlusioninc/crates#757 - I am still not sure how to correctly do what I described there. Now that ZeroizeOnDrop exists, and a third-party SecretDataType implements it, how should I wrap SecretDataType in my type, which I also want to implement ZeroizeOnDrop? The way I currently do it

struct SecretKey { inner: SecretDataType }
impl ZeroizeOnDrop for SecretKey where SecretDataType: ZeroizeOnDrop;

The second line is a static assertion in case the situation with SecretDataType changes. The problem is that this syntax may go away in the future (rust-lang/rust#48214). If I derive ZeroizeOnDrop for SecretKey, it'll be zeroized twice, which is not ideal. Should I write a Drop impl manually for SecretKey?

@tarcieri
Copy link
Member

tarcieri commented Aug 1, 2022

All you need to do is derive(ZeroizeOnDrop). That's it.

It won't double-zeroize. Fields that impl ZeroizeOnDrop will be skipped by the owning container's derived Drop impl. Fields that impl Zeroize will be zeroized. If fields impl neither, it will cause a compile error.

cc @daxpedda

@tarcieri tarcieri closed this as completed Aug 1, 2022
@fjarri
Copy link
Author

fjarri commented Aug 1, 2022

It won't double-zeroize.

That's awesome, it wasn't clear from the docs.

@daxpedda
Copy link
Contributor

daxpedda commented Aug 1, 2022

It won't double-zeroize. Fields that impl ZeroizeOnDrop will be skipped by the owning container's derived Drop impl. Fields that impl Zeroize will be zeroized. If fields impl neither, it will cause a compile error.

👍 This is exactly how it should work indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants