Skip to content

Make getrandom feature imply rand_core so Generate doctests compile#833

Closed
eligrubb wants to merge 1 commit into
RustCrypto:masterfrom
eligrubb:fix-xaes-rustdoc-tests
Closed

Make getrandom feature imply rand_core so Generate doctests compile#833
eligrubb wants to merge 1 commit into
RustCrypto:masterfrom
eligrubb:fix-xaes-rustdoc-tests

Conversation

@eligrubb

@eligrubb eligrubb commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Issue

Running cargo test (or cargo test --doc) on an individual crate fails to compile the usage doctest:

  error[E0432]: unresolved import `xaes_256_gcm::aead::Generate`
    --> xaes-256-gcm/src/lib.rs
     |
     |     aead::{Aead, AeadCore, Generate, Key, KeyInit},
     |                            ^^^^^^^^ no `Generate` in the root
     |
  note: found an item that was configured out
     | pub use common::{Generate, rand_core};
     |                  ^^^^^^^^   (gated behind the `rand_core` feature)

  error[E0599]: no associated function named `generate` found ...

See #755 for more details.

Fix

Generate is exported by aead under the aead/rand_core feature. Each AEAD crate currently enables the aead/rand_core feature only under their own rand_core feature. To fix, chain each crate's getrandom feature into its own rand_core feature, which transitively enables aead/rand_core:

  # before
  getrandom = ["aead/getrandom"]
  # after
  getrandom = ["aead/getrandom", "rand_core"]

This matches the mgm crate which already follows this convention.

Crates touched:

  • aes-gcm, aes-gcm-siv, aes-siv, ascon-aead128, belt-dwp, ccm, chacha20poly1305, deoxys, eax, ocb3: ["aead/getrandom"] → ["aead/getrandom", "rand_core"]
  • xaes-256-gcm: ["aes-gcm/getrandom"] → ["aead/getrandom", "aes-gcm/getrandom", "rand_core"]

Testing

  • Each crate's doctests now pass standalone: cargo test --doc -p for all 11.
  • cargo test --workspace still passes

Note

Alternative, simpler upstream fix may exist, all getrandom features already enable aead/getrandom. If upstream, aead feature aead/getrandom implied aead/rand_core, this would not be necessary. See traits PR#2450 for a proposal of how this would look.

@eligrubb

Copy link
Copy Markdown
Contributor Author

Closing in favor of traits PR#2452 which solves this problem upstream. aead dependency version will need to be bumped before tests are fixed and #755 can be closed.

@eligrubb eligrubb closed this Jun 17, 2026
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.

1 participant