Replace `RAD_DEBUG` with `RAD_SEED`

The latter is strictly more powerful.
This commit is contained in:
Alexis Sellier 2023-01-25 17:09:16 +01:00
parent a3f4c2ec67
commit 0a9bb23e4e
No known key found for this signature in database
3 changed files with 21 additions and 6 deletions

View File

@ -94,7 +94,10 @@ fn rad_auth() {
"examples/rad-auth.md", "examples/rad-auth.md",
Path::new("."), Path::new("."),
None, None,
[("RAD_DEBUG", "1")], [(
"RAD_SEED",
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
)],
) )
.unwrap(); .unwrap();
} }

View File

@ -499,11 +499,20 @@ pub mod keypair {
/// Generate a new keypair using OS randomness. /// Generate a new keypair using OS randomness.
pub fn generate() -> KeyPair { pub fn generate() -> KeyPair {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
if std::env::var("RAD_DEBUG").is_ok() { if let Ok(seed) = std::env::var("RAD_SEED") {
// Generate a test keypair that is always the same. // Generate a keypair based on the given environment variable.
// This is useful for debugging and testing, since the // This is useful for debugging and testing, since the
// public key is known in advance. // public key can be known in advance.
return KeyPair::from_seed(Seed::new([0xff; 32])); let seed = (0..seed.len())
.step_by(2)
.map(|i| u8::from_str_radix(&seed[i..i + 2], 16))
.collect::<Result<Vec<u8>, _>>()
.expect("generate: invalid hexadecimal value set in `RAD_SEED`");
let seed: [u8; 32] = seed
.try_into()
.expect("generate: invalid seed length set in `RAD_SEED`");
return KeyPair::from_seed(Seed::new(seed));
} }
KeyPair::generate() KeyPair::generate()
} }

View File

@ -27,7 +27,10 @@ pub fn seed(dir: &Path) -> Context {
let rad_home = dir.join("radicle"); let rad_home = dir.join("radicle");
env::set_var("RAD_PASSPHRASE", PASSWORD); env::set_var("RAD_PASSPHRASE", PASSWORD);
env::set_var("RAD_DEBUG", "1"); env::set_var(
"RAD_SEED",
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
);
fs::create_dir_all(&workdir).unwrap(); fs::create_dir_all(&workdir).unwrap();
fs::create_dir_all(&rad_home).unwrap(); fs::create_dir_all(&rad_home).unwrap();