Skip to content

Commit

Permalink
Pipe print functionality to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Stentonian committed May 28, 2024
1 parent a6654bc commit 67d1468
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ pub enum Command {
/// Hash digest/bytes for the root node of the tree.
#[arg(short, long, value_parser = H256::from_str, value_name = "BYTES")]
root_hash: H256,

/// Create a json file containing all the path information, and print
/// the same path information to stdout.
#[arg(long, short, action)]
show_path: bool,
},

/// Verify the root node of a DAPOL tree.
Expand Down
43 changes: 32 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use dapol::{
cli::{BuildKindCommand, Cli, Command},
initialize_machine_parallelism,
utils::{activate_logging, Consume, IfNoneThen, LogOnErr, LogOnErrUnwrap},
AggregationFactor, DapolConfig, DapolConfigBuilder, DapolTree, EntityIdsParser, InclusionProof, InclusionProofFileType,
AggregationFactor, DapolConfig, DapolConfigBuilder, DapolTree, EntityIdsParser, InclusionProof,
InclusionProofFileType,
};
use patharg::InputArg;

Expand Down Expand Up @@ -107,7 +108,9 @@ fn main() {
.generate_inclusion_proof(&entity_id)
.log_on_err_unwrap();

proof.serialize(&entity_id, dir.clone(), InclusionProofFileType::Json).log_on_err_unwrap();
proof
.serialize(&entity_id, dir.clone(), InclusionProofFileType::Json)
.log_on_err_unwrap();
}
}

Expand Down Expand Up @@ -168,21 +171,39 @@ fn main() {
.generate_inclusion_proof_with(&entity_id, aggregation_factor.clone())
.log_on_err_unwrap();

proof.serialize(&entity_id, dir.clone(), file_type.clone()).log_on_err_unwrap();
proof
.serialize(&entity_id, dir.clone(), file_type.clone())
.log_on_err_unwrap();
}
}
Command::VerifyInclusionProof {
file_path,
root_hash,
show_path,
} => {
let proof = InclusionProof::deserialize(
file_path
.into_path()
.expect("Expected file path, not stdin"),
)
.log_on_err_unwrap();

proof.verify(root_hash).log_on_err_unwrap();
let file_path = file_path
.into_path()
.expect("Expected file path, not stdin");

let proof = InclusionProof::deserialize(file_path.clone()).log_on_err_unwrap();

if show_path {
proof
.verify_and_show_path_info(
root_hash,
file_path
.parent()
.expect("Expected file_path to have a parent")
.to_path_buf(),
file_path
.file_name()
.expect("Expected file_path to have a file name")
.to_os_string(),
)
.log_on_err_unwrap();
} else {
proof.verify(root_hash).log_on_err_unwrap();
}
}
Command::VerifyRoot { root_pub, root_pvt } => {
let public_root_data = DapolTree::deserialize_public_root_data(
Expand Down

0 comments on commit 67d1468

Please sign in to comment.