diff options
| author | Jokler <jokler@protonmail.com> | 2020-03-22 18:55:40 +0100 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-03-22 18:55:40 +0100 |
| commit | 595232693c270e8c6c85d04ce341676e96682c6f (patch) | |
| tree | 36cc683c71d73dd7bec019081827e36dd329a6ac | |
| parent | 08794f7f7bfd226c4b68b141be14e2405ce61d03 (diff) | |
| download | pokebot-595232693c270e8c6c85d04ce341676e96682c6f.tar.gz pokebot-595232693c270e8c6c85d04ce341676e96682c6f.zip | |
Add flag to increase identity security levels
| -rw-r--r-- | src/main.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 6442005..4fd2b0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,9 @@ pub struct Args { help = "Generate 'count' identities" )] gen_id_count: Option<u8>, + /// Increases the security level of all identities in the config file + #[structopt(short, long = "increase-security-level")] + wanted_level: Option<u8>, #[structopt( short = "a", long = "address", @@ -103,6 +106,27 @@ fn run() -> Result<(), Box<dyn std::error::Error>> { return Ok(()); } + if let Some(level) = args.wanted_level { + if let Some(id) = &mut config.id { + info!("Upgrading master identity"); + id.upgrade_level(level).expect("can upgrade level"); + } + + if let Some(ids) = &mut config.ids { + let len = ids.len(); + for (i, id) in ids.iter_mut().enumerate() { + info!("Upgrading bot identity {}/{}", i + 1, len); + id.upgrade_level(level).expect("can upgrade level"); + } + } + + let toml = toml::to_string(&config)?; + let mut file = File::create(&args.config_path)?; + file.write_all(toml.as_bytes())?; + + return Ok(()); + } + if config.id.is_none() || config.ids.is_none() { error!("Failed to find required identites, try running with `-g`"); return Ok(()); |
