Module tor_llcrypto::util::rand_compat[][src]

Expand description

Compatibility utilities for working with libraries that consume older versions of rand_core.

The dalek-crypto libraries are currently stuck on rand_core 0.5.1, but everywhere else in Arti we want to use the latest rand_core (0.6.2 as of this writing). The extension trait in this module lets us do so.

Example:

As of May 2021, if you’re using the current version of [x25519-dalek], and the latest rand_core, then you can’t use this code, because of the compatibility issue mentioned above.

use rand_core::OsRng;
use x25519_dalek::EphemeralSecret;

let my_secret = EphemeralSecret::new(OsRng);

But instead, you can wrap the random number generator using the RngCompatExt extension trait.

use tor_llcrypto::util::rand_compat::RngCompatExt;
use rand_core::OsRng;
use x25519_dalek::EphemeralSecret;

let my_secret = EphemeralSecret::new(OsRng.rng_compat());

The wrapped RNG can be used with the old version of the RngCode trait, as well as the new one.

Structs

RngWrapper

A new-style Rng, wrapped for backward compatibility.

Traits

RngCompatExt

Extension trait for the current versions of RngCore; adds a compatibility-wrappper function.