Include keys.json as static data
This commit is contained in:
parent
bd51609f05
commit
ca8e830f0a
1 changed files with 21 additions and 14 deletions
27
src/cli.rs
27
src/cli.rs
|
@ -6,7 +6,7 @@ use openssl::{
|
|||
bn::{BigNum, MsbOption},
|
||||
ec::{EcGroup, EcPoint},
|
||||
};
|
||||
use serde_json::from_reader;
|
||||
use serde_json::{from_reader, from_str};
|
||||
|
||||
use crate::{bink1998, crypto::initialize_elliptic_curve};
|
||||
|
||||
|
@ -35,8 +35,8 @@ pub struct Options {
|
|||
num_keys: i32,
|
||||
|
||||
/// Specify which keys file to load
|
||||
#[arg(short = 'f', long = "file", default_value = "keys.json")]
|
||||
keys_filename: String,
|
||||
#[arg(short = 'f', long = "file")]
|
||||
keys_filename: Option<String>,
|
||||
|
||||
/// Installation ID used to generate confirmation ID
|
||||
#[arg(short, long)]
|
||||
|
@ -137,21 +137,28 @@ impl Cli {
|
|||
}
|
||||
|
||||
fn validate_command_line(options: &mut Options) -> Result<serde_json::Value> {
|
||||
let keys = {
|
||||
if let Some(filename) = &options.keys_filename {
|
||||
if options.verbose {
|
||||
println!("Loading keys file {}", options.keys_filename);
|
||||
println!("Loading keys file {}", filename);
|
||||
}
|
||||
|
||||
let keys = Self::load_json(&options.keys_filename)?;
|
||||
let keys = Self::load_json(filename)?;
|
||||
|
||||
if options.verbose {
|
||||
println!("Loaded keys from {} successfully", options.keys_filename);
|
||||
println!("Loaded keys from {} successfully", filename);
|
||||
}
|
||||
|
||||
keys
|
||||
} else {
|
||||
from_str(std::include_str!("../keys.json"))?
|
||||
}
|
||||
};
|
||||
|
||||
if options.list {
|
||||
let products = keys["Products"].as_object().ok_or(anyhow!(
|
||||
"`Products` object not found in {}",
|
||||
options.keys_filename
|
||||
))?;
|
||||
let products = keys["Products"]
|
||||
.as_object()
|
||||
.ok_or(anyhow!("`Products` object not found in keys",))?;
|
||||
for (key, value) in products.iter() {
|
||||
println!("{}: {}", key, value["BINK"]);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue