dalek-cryptography / curve25519-dalek

A pure-Rust implementation of group operations on Ristretto and Curve25519
Other
850 stars 416 forks source link

docs.rs homepage examples use `rand_core` crate option, but do not mention its existence #633

Closed samuela closed 3 months ago

samuela commented 4 months ago

I'm attempting to follow the documentation and have the following file:

use ed25519_dalek::SigningKey;
use rand::rngs::OsRng;

fn main() {
  let mut csprng = OsRng;
  let signing_key: SigningKey = SigningKey::generate(&mut csprng);
}

which I'm attempting to build against ed25519_dalek 2.1.1 and rand 0.8.5 but I'm getting the following error:

error[E0599]: no function or associated item named `generate` found for struct `SigningKey` in the current scope
 --> src/bin/foo.rs:6:45
  |
6 |   let signing_key: SigningKey = SigningKey::generate(&mut csprng);
  |                                             ^^^^^^^^ function or associated item not found in `SigningKey`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `cherami` (bin "foo") due to previous error
tarcieri commented 4 months ago

I agree that example is deficient and doesn't fully explain everything you need to do for the generate method to be available.

For more information, see the documentation here, note "available on crate feature rand_core only":

https://docs.rs/ed25519-dalek/latest/ed25519_dalek/struct.SigningKey.html#method.generate

Screenshot 2024-02-22 at 6 34 39 PM

Solution: you need to enable the rand_core crate feature in Cargo.toml:

[dependencies]
ed25519-dalek = { version = "2", features = ["rand_core"] }
samuela commented 4 months ago

Thanks @tarcieri ! That indeed solves the compilation error. I was not aware of the rand_core option after reading https://docs.rs/ed25519-dalek/latest/ed25519_dalek/.

I will update the issue title to reflect a docs issue, instead of a compilation one.