mirror of
https://github.com/mii443/RustySecrets.git
synced 2025-08-23 08:45:27 +00:00
catch invalid encoding parameters
This commit is contained in:
@ -205,8 +205,9 @@ fn main() {
|
|||||||
let mut opts = Options::new();
|
let mut opts = Options::new();
|
||||||
opts.optflag("h", "help", "print this help text");
|
opts.optflag("h", "help", "print this help text");
|
||||||
opts.optflag("d", "decode", "for decoding");
|
opts.optflag("d", "decode", "for decoding");
|
||||||
opts.optopt("e", "encode", "for encoding, K is the required number of shares, \
|
opts.optopt("e", "encode", "for encoding, K is the required number of \
|
||||||
N is the number of shares to generate. 1 <= K <= N <= 255", "K,N");
|
shares for decoding, N is the number of shares \
|
||||||
|
to generate. 1 <= K <= N <= 255", "K,N");
|
||||||
let opt_matches = match opts.parse(args.tail()) {
|
let opt_matches = match opts.parse(args.tail()) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => panic!(f.to_string())
|
Err(f) => panic!(f.to_string())
|
||||||
@ -229,7 +230,11 @@ fn main() {
|
|||||||
(true, false) => {
|
(true, false) => {
|
||||||
if let Some(param) = opt_matches.opt_str("e") {
|
if let Some(param) = opt_matches.opt_str("e") {
|
||||||
if let Some((k,n)) = parse_k_n(&*param) {
|
if let Some((k,n)) = parse_k_n(&*param) {
|
||||||
|
if 0 < k && k <= n {
|
||||||
Ok(Action::Encode(k,n))
|
Ok(Action::Encode(k,n))
|
||||||
|
} else {
|
||||||
|
Err("Invalid encoding parameters K,N")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Err("Could not parse K,N parameters")
|
Err("Could not parse K,N parameters")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user