-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: command line interface #21
Comments
This one wont be too hard. It will simply involve a lot of console input scanning and openssl dgst -sha256 /path/to/your/file.txt We want our library for now to expose a CLI that would allow it to be used in a similar manner above: capycrypt compute_sha3_hash "So long and thanks for all the fish" -256 Where 256 is the security strength passed after the message to digest. |
For writing a CLI for the library, or other functionalities that use the public API of the library, one needs to define a SecParam enum in their own code and pass it as an argument to the function (for example, However, since functions like If this is correct, I can proceed to open an issue on this. |
Yeah I think thats exactly correct. The CLI can have machinery behind the scenes that can parse the input from the arguments passed into it. So we really want this syntax for a good CLI:
The CLI can parse that 256 into the supported enum behind the scenes and then throw an error back if it was an unsupported value |
heres a more up-to-date example of how the initial CLI can be built: use structopt::StructOpt;
use capycrypt::{Hashable, Message, SecParam, OperationError};
#[derive(Debug, StructOpt)]
#[structopt(name = "capycrypt-cli", about = "A simple hashing CLI")]
enum Command {
#[structopt(name = "compute_sha3_hash")]
Sha3 {
#[structopt(help = "The input string to hash")]
input: String,
#[structopt(help = "Security parameter for the SHA3 hash", short, long, default_value = "256")]
sec_param: String, // Changed to String to directly parse into SecParam later
},
}
fn main() {
let result = Command::from_args();
match result {
Command::Sha3 { input, sec_param } => {
let mut data = Message::new(&mut input.into_bytes());
let sec_param = match sec_param.as_str() {
"224" => SecParam::D224,
"256" => SecParam::D256,
"384" => SecParam::D384,
"512" => SecParam::D512,
_ => {
eprintln!("Unsupported security parameter. Use 224, 256, 384, or 512.");
return;
}
};
match data.compute_hash_sha3(&sec_param) {
Ok(_) => match data.digest {
Some(digest) => println!("Hash: {}", hex::encode(digest.to_vec())),
None => eprintln!("Error: Hash computation failed"),
},
Err(OperationError) => eprintln!("An error occurred during hash computation."),
}
} // Next command here, i.e., compute tagged hash
}
} This how you could build it out while ensuring that the security parameter is instantiated correctly |
creating an openssl style cli would increase the accessibility and usability of this library
The text was updated successfully, but these errors were encountered: