Simplify share threshold and secret length consistency validation

I think that using hashmaps and hash sets was overkill and made the code much
longer and complicated than it needed to be.

The new code also produces more useful error messages that will hopefully help
users identify which share(s) are causing the inconsistency.
This commit is contained in:
Noah Vesely
2018-03-29 00:39:24 -06:00
committed by Romain Ruetschi
parent c437775169
commit 88743caad8
3 changed files with 46 additions and 71 deletions

View File

@ -67,8 +67,8 @@ fn test_recover_duplicate_shares_number() {
}
#[test]
#[should_panic(expected = "IncompatibleDataLengths")]
fn test_recover_incompatible_data_lengths() {
#[should_panic(expected = "InconsistentSecretLengths")]
fn test_recover_inconsistent_secret_lengths() {
let share1 = "2-1-CgnlCxRNtnkzENE".to_string();
let share2 = "2-2-ChbG46L1zRszs0PPn63XnnupmZTcgYJ3".to_string();
@ -77,6 +77,17 @@ fn test_recover_incompatible_data_lengths() {
recover_secret(&shares, false).unwrap();
}
#[test]
#[should_panic(expected = "InconsistentThresholds")]
fn test_inconsistent_thresholds() {
let share1 = "2-1-CgnlCxRNtnkzENE".to_string();
let share2 = "3-2-CgkAnUgP3lfwjyM".to_string();
let shares = vec![share1, share2];
recover_secret(&shares, false).unwrap();
}
#[test]
#[should_panic(expected = "MissingShares")]
fn test_recover_too_few_shares() {