[−][src]Struct sharks::Sharks
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]);
Methods
impl Sharks[src]
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]
T: IntoIterator<Item = &'a Share>,
T::IntoIter: Iterator<Item = &'a Share>,
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());
Auto Trait Implementations
impl RefUnwindSafe for Sharks
impl Send for Sharks
impl Sync for Sharks
impl Unpin for Sharks
impl UnwindSafe for Sharks
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,