Skip to content

Commit 250323c

Browse files
More fuzzer fixes
1 parent bcbc669 commit 250323c

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

fuzz/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ cargo-fuzz = true
1111
[dependencies]
1212
rand = "0.6.1"
1313
rand_pcg = "0.1.1"
14-
ring = "0.13.5"
14+
sha2 = "0.10.6"
15+
1516
[dependencies.base64]
1617
path = ".."
1718
[dependencies.libfuzzer-sys]

fuzz/fuzzers/roundtrip_no_pad.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
extern crate libfuzzer_sys;
44
extern crate base64;
55

6-
use base64::engine::fast_portable;
6+
use base64::engine::{self, fast_portable};
77

88
fuzz_target!(|data: &[u8]| {
99
let config = fast_portable::FastPortableConfig::new()
1010
.with_encode_padding(false)
11-
.with_decode_padding_mode(fast_portable::DecodePaddingMode::RequireNone);
11+
.with_decode_padding_mode(engine::DecodePaddingMode::RequireNone);
1212
let engine = fast_portable::FastPortable::from(&base64::alphabet::STANDARD, config);
1313

1414
let encoded = base64::encode_engine(&data, &engine);

fuzz/fuzzers/utils.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
extern crate rand;
22
extern crate rand_pcg;
3-
extern crate ring;
3+
extern crate sha2;
44

5-
use base64::{alphabet, engine::fast_portable};
5+
use base64::{alphabet, engine::{self, fast_portable}};
66
use self::rand::{Rng, SeedableRng};
77
use self::rand_pcg::Pcg32;
8-
use self::ring::digest;
8+
use self::sha2::Digest as _;
99

1010
pub fn random_engine(data: &[u8]) -> fast_portable::FastPortable {
1111
// use sha256 of data as rng seed so it's repeatable
12-
let sha = digest::digest(&digest::SHA256, data);
12+
let mut hasher = sha2::Sha256::new();
13+
hasher.update(data);
14+
let sha = hasher.finalize();
1315

1416
let mut seed: [u8; 16] = [0; 16];
15-
seed.copy_from_slice(&sha.as_ref()[0..16]);
17+
seed.copy_from_slice(&sha.as_slice()[0..16]);
1618

1719
let mut rng = Pcg32::from_seed(seed);
1820

@@ -24,9 +26,9 @@ pub fn random_engine(data: &[u8]) -> fast_portable::FastPortable {
2426

2527
let encode_padding = rng.gen();
2628
let decode_padding = if encode_padding {
27-
fast_portable::DecodePaddingMode::RequireCanonical
29+
engine::DecodePaddingMode::RequireCanonical
2830
} else {
29-
fast_portable::DecodePaddingMode::RequireNone
31+
engine::DecodePaddingMode::RequireNone
3032
};
3133
let config = fast_portable::FastPortableConfig::new()
3234
.with_encode_padding(encode_padding)

0 commit comments

Comments
 (0)