feat: initial release of ucobs 0.1.0
μCOBS — Consistent Overhead Byte Stuffing encoder/decoder. no_std, zero-alloc, spec-compliant (Cheshire & Baker 1999). 44 tests + doctests, property-based testing, fuzz targets, cross-validation against corncobs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
9 files changed
+790
No files matched your search
@@ -0,0 +1,9 @@
|
||||
//! Fuzz target: feed arbitrary bytes to decode(). Must never panic.
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let mut buf = [0u8; 2048];
|
||||
// Must not panic — may return None on invalid input.
|
||||
let _ = ucobs::decode(data, &mut buf);
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
//! Fuzz target: encode then decode arbitrary input. Output must match input.
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if data.len() > 1024 {
|
||||
return; // skip huge inputs to keep fuzzing fast
|
||||
}
|
||||
|
||||
let max_enc = ucobs::max_encoded_len(data.len()) + 1;
|
||||
let mut enc_buf = vec![0u8; max_enc];
|
||||
|
||||
let enc_len = match ucobs::encode(data, &mut enc_buf) {
|
||||
Some(n) => n,
|
||||
None => return, // encode failed (buffer too small shouldn't happen, but skip)
|
||||
};
|
||||
let encoded = &enc_buf[..enc_len];
|
||||
|
||||
// Encoded output must never contain 0x00.
|
||||
assert!(!encoded.contains(&0x00), "encoded contains sentinel");
|
||||
|
||||
let mut dec_buf = vec![0u8; data.len() + 1];
|
||||
let dec_len = ucobs::decode(encoded, &mut dec_buf)
|
||||
.expect("decode failed after successful encode");
|
||||
|
||||
assert_eq!(
|
||||
&dec_buf[..dec_len], data,
|
||||
"round-trip mismatch: encode→decode produced different output"
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user