mirror of
https://github.com/mii443/RustySecrets.git
synced 2025-08-22 16:25:32 +00:00
Add ErrorKind::ShareParsingInvalidShareThreshold
Ensures that threshold > 2 during the parsing process, since we ensure the same during the splitting process.
This commit is contained in:
committed by
Romain Ruetschi
parent
cdcf012a59
commit
55b7c78a3a
@ -92,6 +92,11 @@ error_chain! {
|
||||
display("Found invalid share identifier ({})", share_id)
|
||||
}
|
||||
|
||||
ShareParsingInvalidShareThreshold(k: u8, id: u8) {
|
||||
description("Threshold k must be bigger than or equal to 2")
|
||||
display("Threshold k must be bigger than or equal to 2. Got k = {} for share identifier {}.", k, id)
|
||||
}
|
||||
|
||||
InvalidSS1Parameters(r: usize, s: usize) {
|
||||
description("Invalid parameters for the SS1 sharing scheme")
|
||||
display("Invalid parameters for the SS1 sharing scheme: r = {}, s = {}.", r, s)
|
||||
|
@ -39,6 +39,8 @@ pub(crate) fn validate_shares<S: IsShare>(shares: Vec<S>) -> Result<(u8, Vec<S>)
|
||||
|
||||
if id < 1 {
|
||||
bail!(ErrorKind::ShareParsingInvalidShareId(id))
|
||||
} else if threshold < 2 {
|
||||
bail!(ErrorKind::ShareParsingInvalidShareThreshold(threshold, id))
|
||||
}
|
||||
|
||||
k_compatibility_sets
|
||||
|
@ -77,6 +77,17 @@ fn test_recover_too_few_shares() {
|
||||
recover_secret(&shares, false).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "ShareParsingInvalidShareThreshold")]
|
||||
fn test_recover_invalid_share_threshold() {
|
||||
let share1 = "1-1-CgnlCxRNtnkzENE".to_string();
|
||||
let share2 = "1-1-CgkAnUgP3lfwjyM".to_string();
|
||||
|
||||
let shares = vec![share1, share2];
|
||||
|
||||
recover_secret(&shares, false).unwrap();
|
||||
}
|
||||
|
||||
// See https://github.com/SpinResearch/RustySecrets/issues/43
|
||||
#[test]
|
||||
fn test_recover_too_few_shares_bug() {
|
||||
|
Reference in New Issue
Block a user