Function shamirsecretsharing::combine_shares[][src]

pub fn combine_shares(shares: &[Vec<u8>]) -> Result<Option<Vec<u8>>, SSSError>

Combine a set of shares and return the original secret

shares must be a slice of share vectors.

The return type will be a Result which will only be Err(err) of the input shares were malformed. When the input shares are of the correct length, this function will always return Ok(_).

Attempts at restoring a secret may fail. Then combine_shares will return Ok(None). This only cases in which this can happen are:

  1. More shares were needed to reach the treshold.
  2. Shares of different sets (corresponding to different secrets) were supplied or some of the shares were tampered with.

If the shares were correct—and a secret could be restored—this function will return Ok(Some(data)), with data being a vector of u8s. This data will be the same length as When it was shared, namely DATA_SIZE (64) bytes.


use shamirsecretsharing::*;

// When `shares` contains a set of valid shares
let restored = combine_shares(&shares).unwrap();
let data = restored.expect("`shares` did not contain a valid set of shares");
println!("Restored some data: {:?}", data);

// When `shares` contains an invalid set of shares
let restored = combine_shares(&shares).unwrap();
assert_eq!(restored, None);