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

Zeroize: Implement Zeroize for MaybeUninit, and remove some unsafe #900

Merged
merged 4 commits into from
Jul 10, 2023

Conversation

elichai
Copy link
Contributor

@elichai elichai commented May 18, 2023

This PR contains a few things:

  1. Implements Zeroize for MaybeUninit<Z> for any Z.
  2. Uses a const to create the 1 in impl_zeroize_for_non_zero instead of using unsafe there.
  3. For Vec<T> uses spare_capacity_mut() instead of manually creating a slice via unsafe. (This bumps MSRV to 1.60, So I understand if it's not wanted right now)
  4. Uses the existing macros to generate more implementations.
  5. On CString use into_bytes_with_nul instead of into_bytes as the latter pops the null character for no reason.
  6. Use the ptr::cast method to cast types

If anything here is controversial I can drop some of the commits and/or split this into multiple PRs.

@tarcieri
Copy link
Member

Looks like this needs an MSRV bump to 1.57, which I'd be OK with.

Otherwise it generally looks good.

@tarcieri
Copy link
Member

tarcieri commented Jul 8, 2023

error[E0658]: use of unstable library feature 'vec_spare_capacity'
   --> zeroize\src\lib.rs:560:14
    |
560 |         self.spare_capacity_mut().zeroize();
    |              ^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #75017 <https://github.com/rust-lang/rust/issues/75017> for more information

Make that MSRV 1.60.

@elichai
Copy link
Contributor Author

elichai commented Jul 9, 2023

error[E0658]: use of unstable library feature 'vec_spare_capacity'
   --> zeroize\src\lib.rs:560:14
    |
560 |         self.spare_capacity_mut().zeroize();
    |              ^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #75017 <https://github.com/rust-lang/rust/issues/75017> for more information

Make that MSRV 1.60.

Ops, fixed :)

@tarcieri tarcieri merged commit 160fa8c into RustCrypto:master Jul 10, 2023
21 checks passed
@elichai elichai deleted the zeroize branch July 10, 2023 08:54
This was referenced Nov 15, 2023
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

Successfully merging this pull request may close these issues.

2 participants