mirror of
https://github.com/mii443/RustySecrets.git
synced 2025-08-22 08:15:50 +00:00
* Update rustfmt compliance Looks like rustfmt has made some improvements recently, so wanted to bring the code up to date. * Add rustfmt to nightly item in Travis matrix * Use Travis Cargo cache * Allow fast_finish in Travis Items that match the `allow_failures` predicate (right now, just Rust nightly), will still finish, but Travis won't wait for them to report a result if the other builds have already finished. * Run kcov in a separate matrix build in Travis * Rework allowed_failures logic We don't want rustfmt to match `allow_failures` just because it needs to use nightly, while we do want nightly to match `allow_failures`. Env vars provide a solution. * Add --all switch to rustfmt Travis * Test building docs in Travis * Use exact Ubuntu dependencies listed for kcov Some of the dependencies we were installing were not listed on https://github.com/SimonKagstrom/kcov/blob/master/INSTALL.md, and we were missing one dependency that was listed there. When `sudo: true` Travis uses Ubuntu Trusty. * No need to build before running kcov kcov builds its own test executables. * Generate `Cargo.lock` w/ `cargo update` before running kcov As noted in aeb3906cce8e3e26c7bc80d6aec417b365f3d2f1 it is not necessary to build the project before running kcov, but kcov does require a `Cargo.lock` file, which can be generated with `cargo update`.
90 lines
2.0 KiB
Rust
90 lines
2.0 KiB
Rust
use std::env;
|
|
use std::fmt;
|
|
use std::fs::File;
|
|
use std::io::Write;
|
|
use std::num::Wrapping;
|
|
use std::path::Path;
|
|
|
|
const POLY: u8 = 0x1D;
|
|
|
|
/// replicates the least significant bit to every other bit
|
|
#[inline]
|
|
fn mask(bit: u8) -> u8 {
|
|
(Wrapping(0u8) - Wrapping(bit & 1)).0
|
|
}
|
|
|
|
/// multiplies a polynomial with x and returns the residual
|
|
/// of the polynomial division with POLY as divisor
|
|
#[inline]
|
|
fn xtimes(poly: u8) -> u8 {
|
|
(poly << 1) ^ (mask(poly >> 7) & POLY)
|
|
}
|
|
|
|
struct Tables {
|
|
exp: [u8; 256],
|
|
log: [u8; 256],
|
|
}
|
|
|
|
fn generate_tables(mut file: &File) {
|
|
let mut tabs = Tables {
|
|
exp: [0; 256],
|
|
log: [0; 256],
|
|
};
|
|
|
|
let mut tmp = 1;
|
|
for power in 0..255usize {
|
|
tabs.exp[power] = tmp;
|
|
tabs.log[tmp as usize] = power as u8;
|
|
tmp = xtimes(tmp);
|
|
}
|
|
tabs.exp[255] = 1;
|
|
|
|
match write!(file, "{}", tabs) {
|
|
Ok(()) => {}
|
|
Err(_) => panic!("Could not format the table. Aborting build."),
|
|
};
|
|
}
|
|
|
|
fn farray(array: [u8; 256], f: &mut fmt::Formatter) -> fmt::Result {
|
|
for (index, value) in array.into_iter().enumerate() {
|
|
try!(write!(f, "{}", value));
|
|
if index != array.len() - 1 {
|
|
try!(write!(f, ","));
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
impl fmt::Display for Tables {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
try!(write!(f, "Tables {{\n"));
|
|
try!(write!(f, " exp: ["));
|
|
try!(farray(self.exp, f));
|
|
try!(write!(f, "],\n"));
|
|
try!(write!(f, " log: ["));
|
|
try!(farray(self.log, f));
|
|
try!(write!(f, "]\n"));
|
|
write!(f, "}};")
|
|
}
|
|
}
|
|
|
|
#[allow(unused_must_use)]
|
|
fn main() {
|
|
let out_dir = env::var("OUT_DIR").unwrap();
|
|
let dest = Path::new(&out_dir).join("nothinghardcoded.rs");
|
|
|
|
let mut f = File::create(&dest).unwrap();
|
|
|
|
write!(
|
|
f,
|
|
"pub struct Tables {{ \
|
|
pub exp: [u8; 256], \
|
|
pub log: [u8; 256] \
|
|
}} \
|
|
\
|
|
pub static TABLES: Tables = "
|
|
);
|
|
|
|
generate_tables(&f);
|
|
}
|