更新libclamav库1.0.0版本

This commit is contained in:
2023-01-14 18:28:39 +08:00
parent b879ee0b2e
commit 45fe15f472
8531 changed files with 1222046 additions and 177272 deletions

View File

@@ -0,0 +1,66 @@
use super::getrandom_impl;
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(feature = "test-in-browser")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[test]
fn test_zero() {
// Test that APIs are happy with zero-length requests
getrandom_impl(&mut [0u8; 0]).unwrap();
}
#[test]
fn test_diff() {
let mut v1 = [0u8; 1000];
getrandom_impl(&mut v1).unwrap();
let mut v2 = [0u8; 1000];
getrandom_impl(&mut v2).unwrap();
let mut n_diff_bits = 0;
for i in 0..v1.len() {
n_diff_bits += (v1[i] ^ v2[i]).count_ones();
}
// Check at least 1 bit per byte differs. p(failure) < 1e-1000 with random input.
assert!(n_diff_bits >= v1.len() as u32);
}
#[test]
fn test_huge() {
let mut huge = [0u8; 100_000];
getrandom_impl(&mut huge).unwrap();
}
// On WASM, the thread API always fails/panics
#[cfg(not(target_arch = "wasm32"))]
#[test]
fn test_multithreading() {
extern crate std;
use std::{sync::mpsc::channel, thread, vec};
let mut txs = vec![];
for _ in 0..20 {
let (tx, rx) = channel();
txs.push(tx);
thread::spawn(move || {
// wait until all the tasks are ready to go.
rx.recv().unwrap();
let mut v = [0u8; 1000];
for _ in 0..100 {
getrandom_impl(&mut v).unwrap();
thread::yield_now();
}
});
}
// start all the tasks
for tx in txs.iter() {
tx.send(()).unwrap();
}
}

View File

@@ -0,0 +1,50 @@
// Test that a custom handler works on wasm32-unknown-unknown
#![cfg(all(
target_arch = "wasm32",
target_os = "unknown",
feature = "custom",
not(feature = "js")
))]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(feature = "test-in-browser")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
use core::{
num::NonZeroU32,
sync::atomic::{AtomicU8, Ordering},
};
use getrandom::{getrandom, register_custom_getrandom, Error};
fn len7_err() -> Error {
NonZeroU32::new(Error::INTERNAL_START + 7).unwrap().into()
}
fn super_insecure_rng(buf: &mut [u8]) -> Result<(), Error> {
// Length 7 buffers return a custom error
if buf.len() == 7 {
return Err(len7_err());
}
// Otherwise, increment an atomic counter
static COUNTER: AtomicU8 = AtomicU8::new(0);
for b in buf {
*b = COUNTER.fetch_add(1, Ordering::Relaxed);
}
Ok(())
}
register_custom_getrandom!(super_insecure_rng);
#[test]
fn custom_rng_output() {
let mut buf = [0u8; 4];
assert_eq!(getrandom(&mut buf), Ok(()));
assert_eq!(buf, [0, 1, 2, 3]);
assert_eq!(getrandom(&mut buf), Ok(()));
assert_eq!(buf, [4, 5, 6, 7]);
}
#[test]
fn rng_err_output() {
assert_eq!(getrandom(&mut [0; 7]), Err(len7_err()));
}

View File

@@ -0,0 +1,11 @@
// Don't test on custom wasm32-unknown-unknown
#![cfg(not(all(
target_arch = "wasm32",
target_os = "unknown",
feature = "custom",
not(feature = "js")
)))]
// Use the normal getrandom implementation on this architecture.
use getrandom::getrandom as getrandom_impl;
mod common;

View File

@@ -0,0 +1,15 @@
// We only test the RDRAND-based RNG source on supported architectures.
#![cfg(any(target_arch = "x86_64", target_arch = "x86"))]
// rdrand.rs expects to be part of the getrandom main crate, so we need these
// additional imports to get rdrand.rs to compile.
use getrandom::Error;
#[macro_use]
extern crate cfg_if;
#[path = "../src/rdrand.rs"]
mod rdrand;
#[path = "../src/util.rs"]
mod util;
use rdrand::getrandom_inner as getrandom_impl;
mod common;