Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,33 @@ edition = "2021"

[dependencies]
aes = "0.8.4"
ahash = "0.8.11"
ahash = { version = "0.8.11", default-features = false, features = ["std"] }
base64 = "0.22.1"
byteorder = "1.5"
cbc = "0.1.2"
cfb = "0.10.0"
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
encoding_rs = "0.8.35"
fancy-regex = "0.14.0"
getrandom = { version = "0.2.15" }
hmac = "0.12.1"
html_parser = "0.7.0"
image = { version = "0.25.5", optional = true }
lazy_static = "1.5.0"
md-5 = "0.10.6"
rand = { version = "0.9.0", default-features = false, features = ["small_rng"] }
regex = "1.11.1"
sha2 = "0.10.8"
thin-vec = "0.2.13"
thousands = "0.2.0"
quick-xml = { version = "0.37.1", features = ["serialize"] }
zip = { version = "2.2.1", default-features = false, features = ["deflate"] }

getrandom = { version = "0.2.15", optional = true }

[lib]
doctest = false

[features]
js = ["getrandom/js"]
runtime-rng = ["getrandom"]
default = ["image"]
6 changes: 3 additions & 3 deletions src/helper/crypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,21 +480,21 @@ fn hash(algorithm: &str, buffers: Vec<&[u8]>) -> Result<Vec<u8>, String> {
#[inline]
fn gen_random_16() -> Vec<u8> {
let buf: &mut [u8] = &mut [0; 16];
getrandom::getrandom(buf);
crate::random::getrandom(buf);
buf.to_vec()
}

#[inline]
fn gen_random_32() -> Vec<u8> {
let buf: &mut [u8] = &mut [0; 32];
getrandom::getrandom(buf);
crate::random::getrandom(buf);
buf.to_vec()
}

#[inline]
fn gen_random_64() -> Vec<u8> {
let buf: &mut [u8] = &mut [0; 64];
getrandom::getrandom(buf);
crate::random::getrandom(buf);
buf.to_vec()
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ extern crate base64;
extern crate byteorder;
extern crate cbc;
extern crate cfb;
extern crate getrandom;
extern crate hmac;
extern crate html_parser;
extern crate sha2;
Expand All @@ -147,6 +146,7 @@ pub mod reader;
pub mod structs;
pub mod traits;
pub mod writer;
mod random;

pub use self::structs::*;
pub use self::traits::*;
Expand Down
21 changes: 21 additions & 0 deletions src/random.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pub(crate) fn getrandom(buf: &mut [u8]) -> Result<(), String> {
#[cfg(feature = "runtime-rng")]
{
extern crate getrandom;
match getrandom::getrandom(buf) {
Ok(_) => Ok(()),
Err(e) => Err(format!("getrandom error: {}", e)),
}
}
#[cfg(not(feature = "runtime-rng"))]
{
use rand::{RngCore, SeedableRng};
let seed = b"No Runtime RNG HERE!!!!!!!!!!111";
let len = buf.len();
let mut rng = rand::rngs::SmallRng::from_seed(*seed);
for byte in buf.iter_mut() {
*byte = rng.next_u32() as u8;
}
Ok(())
}
}