//! Bytes from an RPKI cache: a stream of RTR PDUs. A cache is trusted for //! its data, not to be free of bugs or to be the cache we meant to reach. #![no_main] use bgp_rpki::rtr::Pdu; use bytes::BytesMut; use libfuzzer_sys::fuzz_target; fuzz_target!(|data: &[u8]| { let mut rest = data; // As the client reads: one PDU after another until one is incomplete // or wrong. while let Ok(Some((version, pdu, used))) = Pdu::decode(rest) { assert!(used >= 8 && used <= rest.len()); // What was read can be shown and written. let _ = format!("{pdu:?}"); let mut out = BytesMut::new(); pdu.encode(version, &mut out); // And what is written reads back as itself. A router key is read // only to be skipped, and an error report is written without the // PDU it complains about. if !matches!(pdu, Pdu::RouterKey | Pdu::ErrorReport { .. }) { assert_eq!(Pdu::decode(&out), Ok(Some((version, pdu, out.len())))); } rest = &rest[used..]; } });