Skip to content

Commit

Permalink
Run clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanjay176 committed May 11, 2019
1 parent 746620a commit d07b6ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions examples/ss_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ fn main() {
let total_shares = 5;
let secret = "HelloWorld123";
let mut ss = SecretSharing::new(
threshold, // Minimum shares required for reconstruction.
total_shares, // Total shares.
Charset::Alphanumeric // Charset of secret.
threshold, // Minimum shares required for reconstruction.
total_shares, // Total shares.
Charset::Alphanumeric, // Charset of secret.
);
let shares = ss.generate_shares(secret).unwrap();
let reconstructed_secret = reconstruct_secret(&shares[0..3].to_vec(), ss).unwrap();
assert_eq!(reconstructed_secret, secret);
}
}
2 changes: 1 addition & 1 deletion src/ss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl SecretSharing {
}

/// Reconstruct secret from shares.
pub fn reconstruct_secret(shares: &Vec<String>, ss: SecretSharing) -> Result<String, SSError> {
pub fn reconstruct_secret(shares: &[String], ss: SecretSharing) -> Result<String, SSError> {
// Not enough shares to reconstruct secret.
if (shares.len() as u32) < ss.threshold() {
return Err(SSError::InsufficientShares);
Expand Down
5 changes: 3 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::needless_range_loop)]
use num::bigint::{BigInt, RandBigInt};
use num::traits::ToPrimitive;
use num::{One, Zero};
Expand Down Expand Up @@ -30,14 +31,14 @@ pub struct Point(BigInt, BigInt);

/// Function which returns vector of prime numbers
fn primes() -> Vec<BigInt> {
vec![3.into(), 7.into(), 31.into(), 127.into(), 8191.into(), 131071.into(), 524287.into(), 2147483647.into(), BigInt::parse_bytes(b"2305843009213693951", 10).unwrap(), BigInt::parse_bytes(b"618970019642690137449562111", 10).unwrap(), BigInt::parse_bytes(b"162259276829213363391578010288127", 10).unwrap(), BigInt::parse_bytes(b"170141183460469231731687303715884105727", 10).unwrap(), BigInt::parse_bytes(b"115792089237316195423570985008687907853269984665640564039457584007913129640233", 10).unwrap(), BigInt::parse_bytes(b"2135987035920910082395021706169552114602704522356652769947041607822219725780640550022962086936603", 10).unwrap(),BigInt::parse_bytes(b"39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990307047", 10).unwrap(), BigInt::parse_bytes(b"6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151", 10).unwrap(), BigInt::parse_bytes(b"531137992816767098689588206552468627329593117727031923199444138200403559860852242739162502265229285668889329486246501015346579337652707239409519978766587351943831270835393219031728127", 10).unwrap(), BigInt::parse_bytes(b"10407932194664399081925240327364085538615262247266704805319112350403608059673360298012239441732324184842421613954281007791383566248323464908139906605677320762924129509389220345773183349661583550472959420547689811211693677147548478866962501384438260291732348885311160828538416585028255604666224831890918801847068222203140521026698435488732958028878050869736186900714720710555703168729087", 10).unwrap()]
vec![3.into(), 7.into(), 31.into(), 127.into(), 8191.into(), 131_071.into(), 524_287.into(), 2_147_483_647.into(), BigInt::parse_bytes(b"2305843009213693951", 10).unwrap(), BigInt::parse_bytes(b"618970019642690137449562111", 10).unwrap(), BigInt::parse_bytes(b"162259276829213363391578010288127", 10).unwrap(), BigInt::parse_bytes(b"170141183460469231731687303715884105727", 10).unwrap(), BigInt::parse_bytes(b"115792089237316195423570985008687907853269984665640564039457584007913129640233", 10).unwrap(), BigInt::parse_bytes(b"2135987035920910082395021706169552114602704522356652769947041607822219725780640550022962086936603", 10).unwrap(),BigInt::parse_bytes(b"39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990307047", 10).unwrap(), BigInt::parse_bytes(b"6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151", 10).unwrap(), BigInt::parse_bytes(b"531137992816767098689588206552468627329593117727031923199444138200403559860852242739162502265229285668889329486246501015346579337652707239409519978766587351943831270835393219031728127", 10).unwrap(), BigInt::parse_bytes(b"10407932194664399081925240327364085538615262247266704805319112350403608059673360298012239441732324184842421613954281007791383566248323464908139906605677320762924129509389220345773183349661583550472959420547689811211693677147548478866962501384438260291732348885311160828538416585028255604666224831890918801847068222203140521026698435488732958028878050869736186900714720710555703168729087", 10).unwrap()]
}

/// Return next prime greater than `val` from the primes list.
pub fn next_prime(val: &BigInt) -> Result<BigInt, SSError> {
primes()
.into_iter()
.skip_while(|x| x <= &&val)
.skip_while(|x| x <= val)
.take(1)
.collect::<Vec<_>>()
.pop()
Expand Down

0 comments on commit d07b6ad

Please sign in to comment.