# Struct sharks::Sharks[−][src]

`pub struct Sharks(pub u8);`

Tuple struct which implements methods to generate shares and recover secrets over a 256 bits Galois Field. Its only parameter is the minimum shares threshold.

Usage example:

```// Set a minimum threshold of 10 shares
let sharks = Sharks(10);
// Obtain an iterator over the shares for secret [1, 2, 3, 4]
let dealer = sharks.dealer(&[1, 2, 3, 4]);
// Get 10 shares
let shares: Vec<Share> = dealer.take(10).collect();
// Recover the original secret!
let secret = sharks.recover(shares.as_slice()).unwrap();
assert_eq!(secret, vec![1, 2, 3, 4]);```

## Implementations

### `impl Sharks`[src]

#### `pub fn dealer_rng<R: Rng>(    &self,     secret: &[u8],     rng: &mut R) -> impl Iterator<Item = Share>`[src]

This method is useful when `std` is not available. For typical usage see the `dealer` method.

Given a `secret` byte slice, returns an `Iterator` along new shares. The maximum number of shares that can be generated is 256. A random number generator has to be provided.

Example:

```// Obtain an iterator over the shares for secret [1, 2]
let mut rng = rand_chacha::ChaCha8Rng::from_seed([0x90; 32]);
let dealer = sharks.dealer_rng(&[1, 2], &mut rng);
// Get 3 shares
let shares: Vec<Share> = dealer.take(3).collect();```

#### `pub fn dealer(&self, secret: &[u8]) -> impl Iterator<Item = Share>`[src]

Given a `secret` byte slice, returns an `Iterator` along new shares. The maximum number of shares that can be generated is 256.

Example:

```// Obtain an iterator over the shares for secret [1, 2]
let dealer = sharks.dealer(&[1, 2]);
// Get 3 shares
let shares: Vec<Share> = dealer.take(3).collect();```

#### `pub fn recover<'a, T>(&self, shares: T) -> Result<Vec<u8>, &str> where    T: IntoIterator<Item = &'a Share>,    T::IntoIter: Iterator<Item = &'a Share>, `[src]

Given an iterable collection of shares, recovers the original secret. If the number of distinct shares is less than the minimum threshold an `Err` is returned, otherwise an `Ok` containing the secret.

Example:

```// Recover original secret from shares
let mut secret = sharks.recover(&shares);
// Secret correctly recovered
assert!(secret.is_ok());
// Remove shares for demonstration purposes
shares.clear();
secret = sharks.recover(&shares);
// Not enough shares to recover secret
assert!(secret.is_err());```

## Blanket Implementations

### `impl<T, U> TryFrom<U> for T where    U: Into<T>, `[src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

### `impl<T, U> TryInto<U> for T where    U: TryFrom<T>, `[src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.