From d0d9683df8398696147e7ee1fcffb2e4e957008c Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sat, 4 Apr 2020 14:39:19 -0700 Subject: Remove vendored dependencies While it appears that by now we actually can get successful builds without Cargo insisting on Internet access by virtue of using the --frozen flag, maintaining vendored dependencies is somewhat of a pain point. This state will also get worse with upcoming changes that replace argparse in favor of structopt and pull in a slew of new dependencies by doing so. Then there is also the repository structure aspect, which is non-standard due to the way we vendor dependencies and a potential source of confusion. In order to fix these problems, this change removes all the vendored dependencies we have. Delete subrepo argparse/:argparse Delete subrepo base32/:base32 Delete subrepo cc/:cc Delete subrepo cfg-if/:cfg-if Delete subrepo getrandom/:getrandom Delete subrepo lazy-static/:lazy-static Delete subrepo libc/:libc Delete subrepo nitrokey-sys/:nitrokey-sys Delete subrepo nitrokey/:nitrokey Delete subrepo rand/:rand --- rand/rand_xorshift/src/lib.rs | 117 ------------------------------------------ 1 file changed, 117 deletions(-) delete mode 100644 rand/rand_xorshift/src/lib.rs (limited to 'rand/rand_xorshift/src/lib.rs') diff --git a/rand/rand_xorshift/src/lib.rs b/rand/rand_xorshift/src/lib.rs deleted file mode 100644 index b9fef23..0000000 --- a/rand/rand_xorshift/src/lib.rs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The xorshift random number generator. - -#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", - html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://rust-random.github.io/rand/")] - -#![deny(missing_docs)] -#![deny(missing_debug_implementations)] - -#![no_std] - -use core::num::Wrapping as w; -use core::fmt; -use rand_core::{RngCore, SeedableRng, Error, impls, le}; -#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; - -/// An Xorshift random number generator. -/// -/// The Xorshift[^1] algorithm is not suitable for cryptographic purposes -/// but is very fast. If you do not know for sure that it fits your -/// requirements, use a more secure one such as `StdRng` or `OsRng`. -/// -/// [^1]: Marsaglia, George (July 2003). -/// ["Xorshift RNGs"](https://www.jstatsoft.org/v08/i14/paper). -/// *Journal of Statistical Software*. Vol. 8 (Issue 14). -#[derive(Clone)] -#[cfg_attr(feature="serde1", derive(Serialize,Deserialize))] -pub struct XorShiftRng { - x: w, - y: w, - z: w, - w: w, -} - -// Custom Debug implementation that does not expose the internal state -impl fmt::Debug for XorShiftRng { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "XorShiftRng {{}}") - } -} - -impl RngCore for XorShiftRng { - #[inline] - fn next_u32(&mut self) -> u32 { - let x = self.x; - let t = x ^ (x << 11); - self.x = self.y; - self.y = self.z; - self.z = self.w; - let w_ = self.w; - self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8)); - self.w.0 - } - - #[inline] - fn next_u64(&mut self) -> u64 { - impls::next_u64_via_u32(self) - } - - #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - impls::fill_bytes_via_next(self, dest) - } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - self.fill_bytes(dest); - Ok(()) - } -} - -impl SeedableRng for XorShiftRng { - type Seed = [u8; 16]; - - fn from_seed(seed: Self::Seed) -> Self { - let mut seed_u32 = [0u32; 4]; - le::read_u32_into(&seed, &mut seed_u32); - - // Xorshift cannot be seeded with 0 and we cannot return an Error, but - // also do not wish to panic (because a random seed can legitimately be - // 0); our only option is therefore to use a preset value. - if seed_u32.iter().all(|&x| x == 0) { - seed_u32 = [0xBAD_5EED, 0xBAD_5EED, 0xBAD_5EED, 0xBAD_5EED]; - } - - XorShiftRng { - x: w(seed_u32[0]), - y: w(seed_u32[1]), - z: w(seed_u32[2]), - w: w(seed_u32[3]), - } - } - - fn from_rng(mut rng: R) -> Result { - let mut b = [0u8; 16]; - loop { - rng.try_fill_bytes(&mut b[..])?; - if !b.iter().all(|&x| x == 0) { - break; - } - } - - Ok(XorShiftRng { - x: w(u32::from_le_bytes([b[0], b[1], b[2], b[3]])), - y: w(u32::from_le_bytes([b[4], b[5], b[6], b[7]])), - z: w(u32::from_le_bytes([b[8], b[9], b[10], b[11]])), - w: w(u32::from_le_bytes([b[12], b[13], b[14], b[15]])), - }) - } -} -- cgit v1.2.1