[−][src]Function ssss::unlock
pub fn unlock(shares: &HashMap<u8, Vec<u8>>) -> Result<Vec<u8>, Error>
Attempt to unlock the secret given some shares
.
Notes
- If there aren't enough shares to meet the threshold defined when the shares were created the resulting vector of bytes will be gibberish.
- If there are more shares supplied than were defined when the shares were created the resulting vector of bytes will be gibberish.
Errors
- This function will generate an error if the
shares
map is empty. - This function will generate an error if the
shares
within the map are not all the same length.
Example
// Generate 5 shares from the given secret let secret = "s3(r37".as_bytes(); let mut shares = gen_shares(&SSSSConfig::default(), secret)?; assert_eq!(shares.len(), 5); // Remove a couple shares to show 3 will unlock the secret (4 or 5 shares will as well) let _ = shares.remove(&2); let _ = shares.remove(&5); assert_eq!(shares.len(), 3); let unlocked_secret = unlock(&shares)?; assert_eq!(secret, unlocked_secret); // Remove one more to show 2 shares will not unlock the secret let _ = shares.remove(&1); assert_eq!(shares.len(), 2); let who_knows = unlock(&shares)?; assert_ne!(secret, who_knows);