mirror of
https://github.com/mii443/RustySecrets.git
synced 2025-08-22 16:25:32 +00:00
@ -6,7 +6,7 @@ use std::fmt;
|
||||
use std::io;
|
||||
use std::num;
|
||||
|
||||
/// Error struct used for generating an io:Error from a generic description.
|
||||
/// Error struct used for generating an `io::Error` from a generic description.
|
||||
#[derive(Debug)]
|
||||
pub struct Error {
|
||||
descr: &'static str,
|
||||
@ -39,15 +39,15 @@ impl convert::From<Error> for io::Error {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an io:Error from description string and optional detail string.
|
||||
/// Particularly useful in Result expressions.
|
||||
/// Returns an `io::Error` from description string and optional detail string.
|
||||
/// Particularly useful in `Result` expressions.
|
||||
pub fn other_io_err(descr: &'static str, detail: Option<String>) -> io::Error {
|
||||
convert::From::from(
|
||||
Error::new(descr, detail)
|
||||
)
|
||||
}
|
||||
|
||||
/// maps a ParseIntError to an io::Error
|
||||
/// maps a `ParseIntError` to an `io::Error`
|
||||
pub fn pie2io(p: num::ParseIntError) -> io::Error {
|
||||
convert::From::from(
|
||||
Error::new("Integer parsing error", Some(p.to_string()))
|
||||
|
@ -6,7 +6,7 @@ use std::ops::{ Add, Sub, Mul, Div };
|
||||
include!(concat!(env!("OUT_DIR"), "/nothinghardcoded.rs"));
|
||||
|
||||
fn get_tables() -> &'static Tables {
|
||||
return &TABLES;
|
||||
&TABLES
|
||||
}
|
||||
|
||||
/// Type for elements of a finite field with 256 elements
|
||||
|
@ -10,7 +10,7 @@ use self::gf256::Gf256;
|
||||
use std::io;
|
||||
use std::iter::repeat;
|
||||
|
||||
/// Generate generic errors that typeset with io::Error.
|
||||
/// Generate generic errors that typeset with `io::Error`.
|
||||
pub mod custom_error;
|
||||
use self::custom_error::*;
|
||||
|
||||
@ -31,7 +31,7 @@ use self::custom_error::*;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
pub fn generate_shares(k: u8, n: u8, secret: &Vec<u8>) -> io::Result<Vec<String>> {
|
||||
pub fn generate_shares(k: u8, n: u8, secret: &[u8]) -> io::Result<Vec<String>> {
|
||||
if k > n {
|
||||
return Err(other_io_err("Threshold K can not be larger than N", None));
|
||||
}
|
||||
@ -53,7 +53,7 @@ pub fn generate_shares(k: u8, n: u8, secret: &Vec<u8>) -> io::Result<Vec<String>
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn process_shares(shares_strings: Vec<String>) -> io::Result<(u8, Vec<(u8,Vec<u8>)>)> {
|
||||
fn process_shares(shares_strings: Vec<String>) -> io::Result<(u8, Vec<(u8, Vec<u8>)>)> {
|
||||
let mut opt_k_l: Option<(u8, usize)> = None;
|
||||
let mut counter = 0u8;
|
||||
let mut shares: Vec<(u8,Vec<u8>)> = Vec::new();
|
||||
@ -137,7 +137,7 @@ pub fn recover_secret(shares: Vec<String>) -> io::Result<Vec<u8>> {
|
||||
secret.push(lagrange_interpolate(&*col_in, 0u8));
|
||||
}
|
||||
|
||||
return Ok(secret) as io::Result<Vec<u8>>;
|
||||
Ok(secret) as io::Result<Vec<u8>>
|
||||
}
|
||||
|
||||
fn new_vec<T: Clone>(n: usize, x: T) -> Vec<T> {
|
||||
|
Reference in New Issue
Block a user