use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::AcceptChannel, data, read_pos);
- }
+ test_msg!(msgs::AcceptChannel, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::ClosingSigned, data, read_pos);
- }
+ test_msg!(msgs::ClosingSigned, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::CommitmentSigned, data, read_pos);
- }
+ test_msg!(msgs::CommitmentSigned, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::FundingCreated, data, read_pos);
- }
+ test_msg!(msgs::FundingCreated, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::FundingLocked, data, read_pos);
- }
+ test_msg!(msgs::FundingLocked, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::FundingSigned, data, read_pos);
- }
+ test_msg!(msgs::FundingSigned, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::OpenChannel, data, read_pos);
- }
+ test_msg!(msgs::OpenChannel, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::RevokeAndACK, data, read_pos);
- }
+ test_msg!(msgs::RevokeAndACK, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::Shutdown, data, read_pos);
- }
+ test_msg!(msgs::Shutdown, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::MSG_TARGET, data, read_pos);
- }
+ test_msg!(msgs::MSG_TARGET, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::UpdateAddHTLC, data, read_pos);
- }
+ test_msg!(msgs::UpdateAddHTLC, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::UpdateFailHTLC, data, read_pos);
- }
+ test_msg!(msgs::UpdateFailHTLC, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::UpdateFailMalformedHTLC, data, read_pos);
- }
+ test_msg!(msgs::UpdateFailMalformedHTLC, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::UpdateFee, data, read_pos);
- }
+ test_msg!(msgs::UpdateFee, data);
}
#[cfg(feature = "afl")]
use lightning::ln::msgs::{MsgEncodable, MsgDecodable};
mod utils;
-use utils::slice_to_be16;
#[inline]
pub fn do_test(data: &[u8]) {
reset_rng_state();
- let mut read_pos = 0;
- loop {
- test_msg!(msgs::UpdateFulfillHTLC, data, read_pos);
- }
+ test_msg!(msgs::UpdateFulfillHTLC, data);
}
#[cfg(feature = "afl")]
#![macro_use]
-#[allow(dead_code)]
-#[inline]
-pub fn slice_to_be16(v: &[u8]) -> u16 {
- ((v[0] as u16) << 8*1) |
- ((v[1] as u16) << 8*0)
-}
-
#[macro_export]
macro_rules! test_msg {
- ($MsgType: path, $data: ident, $read_pos: ident) => {
- {
- let len = slice_to_be16(get_slice!($data, $read_pos, 2));
- let raw = get_slice!($data, $read_pos, len);
- let cb = decode_msg!($MsgType, raw).encode();
- assert_eq!(&raw[..cb.len()], &cb[..]);
- }
- }
-}
-
-#[macro_export]
-macro_rules! decode_msg {
- ($MsgType: path, $data: expr) => {
- match <($MsgType)>::decode($data) {
- Ok(msg) => msg,
- Err(e) => match e {
- msgs::DecodeError::UnknownRealmByte => return,
- msgs::DecodeError::BadPublicKey => return,
- msgs::DecodeError::BadSignature => return,
- msgs::DecodeError::ExtraAddressesPerType => return,
- msgs::DecodeError::WrongLength => return,
- }
- }
- }
-}
-
-#[macro_export]
-macro_rules! get_slice {
- ($data: ident, $read_pos: ident, $len: expr) => {
+ ($MsgType: path, $data: ident) => {
{
- let slice_len = $len as usize;
- if $data.len() < $read_pos + slice_len {
- return;
+ if let Ok(msg) = <$MsgType as MsgDecodable>::decode($data){
+ let enc = msg.encode();
+ assert_eq!(&$data[..enc.len()], &enc[..]);
}
- $read_pos += slice_len;
- &$data[$read_pos - slice_len..$read_pos]
}
}
}