Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg committed Aug 9, 2024
1 parent 65020ae commit fe493e2
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 841 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 17 additions & 12 deletions coordinator/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,29 @@ pub struct Args {
#[arg(short = 'S', long, value_delimiter = ',')]
pub signers: Vec<String>,

/// The number of participants. If 0, will prompt for a value.
/// The number of participants. If `signers` is specified, it will use the
/// length of `signers`. Otherwise, if 0, it will prompt for a value.
#[arg(short = 'n', long, default_value_t = 0)]
pub num_signers: u16,

/// Public key package to use. Can be a file with a JSON-encoded
/// package, or "". If the file does not exist or if "" is specified,
/// package, or "-". If the file does not exist or if "-" is specified,
/// then it will be read from standard input.
#[arg(short = 'P', long, default_value = "public-key-package.json")]
pub public_key_package: String,

/// The messages to sign. Each instance can be a file with the raw message,
/// "" or "-". If "" or "-" is specified, then it will be read from standard
/// input as a hex string. If none are passed, a single one will be read
/// from standard input.
/// from standard input as a hex string.
#[arg(short = 'm', long)]
pub message: Vec<String>,

/// The randomizers to use. Each instance can be a file with the raw
/// randomizer, "" or "-". If empty or "-" it will be read from standard
/// input as a hex string. If none are passed, random ones will be
/// generated.
/// randomizer, "" or "-". If "" or "-" is specified, then it will be read
/// from standard input as a hex string. If none are passed, random ones
/// will be generated. If one or more are passed, the number should match
/// the `message` parameter.
#[arg(short = 'r', long)]
pub randomizer: Vec<String>,

Expand Down Expand Up @@ -131,10 +133,13 @@ pub struct ProcessedArgs<C: Ciphersuite> {
}

impl<C: Ciphersuite + 'static> ProcessedArgs<C> {
/// Create a ProcessedArgs from a Args.
///
/// Validates inputs and reads/parses arguments.
pub fn new(
args: &Args,
input: &mut dyn BufRead,
logger: &mut dyn Write,
output: &mut dyn Write,
) -> Result<Self, Box<dyn Error>> {
let password = if args.http {
env::var(&args.password).map_err(|_| eyre!("The password argument must specify the name of a environment variable containing the password"))?
Expand All @@ -145,7 +150,7 @@ impl<C: Ciphersuite + 'static> ProcessedArgs<C> {
let num_signers = if !args.signers.is_empty() {
args.signers.len() as u16
} else if args.num_signers == 0 {
writeln!(logger, "The number of participants: ")?;
writeln!(output, "The number of participants: ")?;

let mut participants = String::new();
input.read_line(&mut participants)?;
Expand All @@ -156,15 +161,15 @@ impl<C: Ciphersuite + 'static> ProcessedArgs<C> {

let out = read_from_file_or_stdin(
input,
logger,
output,
"public key package",
&args.public_key_package,
)?;

let public_key_package: PublicKeyPackage<C> = serde_json::from_str(&out)?;

let messages = if args.message.is_empty() {
writeln!(logger, "The message to be signed (hex encoded)")?;
writeln!(output, "The message to be signed (hex encoded)")?;
let mut msg = String::new();
input.read_line(&mut msg)?;
vec![hex::decode(msg.trim())?]
Expand All @@ -173,7 +178,7 @@ impl<C: Ciphersuite + 'static> ProcessedArgs<C> {
.iter()
.map(|filename| {
let msg = if filename == "-" || filename.is_empty() {
writeln!(logger, "The message to be signed (hex encoded)")?;
writeln!(output, "The message to be signed (hex encoded)")?;
let mut msg = String::new();
input.read_line(&mut msg)?;
hex::decode(msg.trim())?
Expand All @@ -195,7 +200,7 @@ impl<C: Ciphersuite + 'static> ProcessedArgs<C> {
.iter()
.map(|filename| {
let randomizer = if filename == "-" || filename.is_empty() {
writeln!(logger, "Enter the randomizer (hex string):")?;
writeln!(output, "Enter the randomizer (hex string):")?;
let mut randomizer = String::new();
input.read_line(&mut randomizer)?;
let bytes = hex::decode(randomizer.trim())?;
Expand Down
Loading

0 comments on commit fe493e2

Please sign in to comment.