Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
larseggert committed Apr 18, 2024
1 parent 5d55f1f commit ed79956
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions neqo-crypto/src/p11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,23 +295,27 @@ thread_local! {
static CURRENT_VALUE: std::cell::Cell<u8> = const { std::cell::Cell::new(0) };
}

/// Fill a buffer with randomness. (Unless compiled with the `disable-random` feature, in which case
/// it fills the buffer with a predictable sequence of bytes.)
#[cfg(feature = "disable-random")]
/// Fill a buffer with a predictable sequence of bytes.
pub fn randomize<B: AsMut<[u8]>>(mut buf: B) -> B {
let m_buf = buf.as_mut();
for v in m_buf.iter_mut() {
*v = CURRENT_VALUE.get();
CURRENT_VALUE.set(v.wrapping_add(1));
}
buf
}

/// Fill a buffer with randomness.
///
/// # Panics
///
/// When `size` is too large or NSS fails.
#[cfg(not(feature = "disable-random"))]
pub fn randomize<B: AsMut<[u8]>>(mut buf: B) -> B {
let m_buf = buf.as_mut();
if cfg!(feature = "disable-random") {
for v in m_buf.iter_mut() {
*v = CURRENT_VALUE.get();
CURRENT_VALUE.set(v.wrapping_add(1));
}
} else {
let len = std::os::raw::c_int::try_from(m_buf.len()).unwrap();
secstatus_to_res(unsafe { PK11_GenerateRandom(m_buf.as_mut_ptr(), len) }).unwrap();
}
let len = std::os::raw::c_int::try_from(m_buf.len()).unwrap();
secstatus_to_res(unsafe { PK11_GenerateRandom(m_buf.as_mut_ptr(), len) }).unwrap();
buf
}

Expand Down
2 changes: 1 addition & 1 deletion neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,7 +1515,7 @@ impl Connection {
} else {
"client_initial"
};
neqo_common::write_item_to_fuzzing_corpus(target, &payload);
neqo_common::write_item_to_fuzzing_corpus(target, &payload[..]);
}

qlog::packet_received(&mut self.qlog, &packet, &payload);
Expand Down

0 comments on commit ed79956

Please sign in to comment.