From 3e89d1b1ca6b065cb324d224ebd1c11c8c2c1b68 Mon Sep 17 00:00:00 2001 From: Romain Ruetschi Date: Fri, 2 Mar 2018 19:16:31 +0100 Subject: [PATCH] Add a test for issue #43. Regardless of threshold, all polynomials are lines due to small syntactic error --- tests/recovery_errors.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/recovery_errors.rs b/tests/recovery_errors.rs index 131a012..7a36dbe 100644 --- a/tests/recovery_errors.rs +++ b/tests/recovery_errors.rs @@ -1,6 +1,6 @@ extern crate rusty_secrets; -use rusty_secrets::sss::recover_secret; +use rusty_secrets::sss::{recover_secret, split_secret}; #[test] #[should_panic(expected = "EmptyShares")] @@ -87,3 +87,25 @@ fn test_recover_too_few_shares() { recover_secret(&shares, false).unwrap(); } + +// See https://github.com/SpinResearch/RustySecrets/issues/43 +#[test] +fn test_recover_too_few_shares_bug() { + let original = b"Test for issue #43".to_vec(); + let shares = split_secret(4, 5, &original, false).unwrap(); + let mut share_1 = shares[0].clone().into_bytes(); + let mut share_2 = shares[3].clone().into_bytes(); + + share_1[0] = '2' as u8; + share_2[0] = '2' as u8; + + let sub_shares = vec![ + String::from_utf8_lossy(&share_1).into_owned(), + String::from_utf8_lossy(&share_2).into_owned(), + ]; + + match recover_secret(&sub_shares, false) { + Err(_) => assert!(true), + Ok(recovered) => assert_ne!(original, recovered), + } +}