use std::io::Cursor;
use std::str::FromStr;
use crate::control::conn::{Conn, UnauthenticatedConn};
#[cfg(feature = "v3")]
use crate::onion::OnionAddressV3;
use crate::utils::{BASE32_ALPHA, block_on, parse_single_key_value, unquote_string};
pub fn fuzz_unquote_string(data: &[u8]) {
if let Ok(data) = std::str::from_utf8(data) {
let (offset, _res) = unquote_string(data);
if let Some(offset) = offset {
assert_eq!(data.as_bytes()[offset], b'"');
}
}
}
pub fn fuzz_parse_single_key_value(data: &[u8]) {
if data.len() < 1 {
return;
}
let must_be_quoted = data[0] % 2 == 0;
let data = &data[1..];
if let Ok(data) = std::str::from_utf8(data) {
let _ = parse_single_key_value(data);
}
}
#[cfg(feature = "control")]
pub fn fuzz_conn_parse_response(data: &[u8]) {
block_on(async move {
let mut s = Cursor::new(data);
let mut c = Conn::new(s);
if let Ok((code, data)) = c.receive_data().await {
assert!(code >= 0 && code <= 999);
}
});
}
#[cfg(feature = "control")]
pub fn fuzz_unauthenticated_conn_parse_protocol_info(data: &[u8]) {
block_on(async move {
let mut s = Cursor::new(data);
let mut c = Conn::new(s);
let mut c = UnauthenticatedConn::from(c);
let _ = c.read_protocol_info().await;
});
}
#[cfg(feature = "v3")]
pub fn fuzz_deserialize_onion_address_v3_from_text(data: &[u8]) {
if let Ok(data) = std::str::from_utf8(data) {
let _ = OnionAddressV3::from_str(data);
}
}