]> git.bitcoin.ninja Git - rust-lightning/commitdiff
use hex::decode instead of extend_vec_from_hex
authorSavil Srivastava <savil@cs.stanford.edu>
Sat, 28 Jul 2018 16:44:15 +0000 (09:44 -0700)
committerSavil Srivastava <savil@cs.stanford.edu>
Sat, 28 Jul 2018 17:09:29 +0000 (10:09 -0700)
26 files changed:
fuzz/Cargo.toml
fuzz/fuzz_targets/chanmon_deser_target.rs
fuzz/fuzz_targets/channel_target.rs
fuzz/fuzz_targets/full_stack_target.rs
fuzz/fuzz_targets/msg_ping_target.rs
fuzz/fuzz_targets/msg_pong_target.rs
fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs
fuzz/fuzz_targets/msg_targets/msg_channel_reestablish_target.rs
fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs
fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs
fuzz/fuzz_targets/msg_targets/msg_error_message_target.rs
fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs
fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs
fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs
fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs
fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs
fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs
fuzz/fuzz_targets/msg_targets/msg_target_template.txt
fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs
fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs
fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs
fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs
fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs
fuzz/fuzz_targets/msg_targets/utils.rs
fuzz/fuzz_targets/peer_crypt_target.rs
fuzz/fuzz_targets/router_target.rs

index 22f4bdcc181a3706ddbaf6260e16ea5fa026aa55..aec5d9a81a868ecb4193a004de8373a13a170c50 100644 (file)
@@ -16,12 +16,13 @@ afl_fuzz = ["afl"]
 honggfuzz_fuzz = ["honggfuzz"]
 
 [dependencies]
+afl = { version = "0.3", optional = true }
 lightning = { path = "..", features = ["fuzztarget"] }
 bitcoin = { version = "0.13", features = ["fuzztarget"] }
-secp256k1 = { version = "0.9", features=["fuzztarget"] }
-rust-crypto = "0.2"
+hex = "0.3.2"
 honggfuzz = { version = "0.5", optional = true }
-afl = { version = "0.3", optional = true }
+rust-crypto = "0.2"
+secp256k1 = { version = "0.9", features=["fuzztarget"] }
 
 [build-dependencies]
 cc = "1.0"
index 0bf86177a1885ca74fe79502c1a1ffaadc1fa527..adf4a3a6ac887195857d92500e90f12c70f8ede6 100644 (file)
@@ -35,29 +35,12 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
-               let mut b = 0;
-               for (idx, c) in hex.as_bytes().iter().enumerate() {
-                       b <<= 4;
-                       match *c {
-                               b'A'...b'F' => b |= c - b'A' + 10,
-                               b'a'...b'f' => b |= c - b'a' + 10,
-                               b'0'...b'9' => b |= c - b'0',
-                               _ => panic!("Bad hex"),
-                       }
-                       if (idx & 1) == 1 {
-                               out.push(b);
-                               b = 0;
-                       }
-               }
-       }
 
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 6b24d700eb02b424b874301ed62e132a0a2f9f7f..683faf0edc65dd30f5b325aaaf72bbaa6023be5f 100644 (file)
@@ -333,29 +333,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
-               let mut b = 0;
-               for (idx, c) in hex.as_bytes().iter().enumerate() {
-                       b <<= 4;
-                       match *c {
-                               b'A'...b'F' => b |= c - b'A' + 10,
-                               b'a'...b'f' => b |= c - b'a' + 10,
-                               b'0'...b'9' => b |= c - b'0',
-                               _ => panic!("Bad hex"),
-                       }
-                       if (idx & 1) == 1 {
-                               out.push(b);
-                               b = 0;
-                       }
-               }
-       }
-
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 6fdac8ad24e080034613b3440cba556db3e5b691..cf84701d4efd945c687dea6cd6a3d6729ed44e2b 100644 (file)
@@ -368,29 +368,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
-               let mut b = 0;
-               for (idx, c) in hex.as_bytes().iter().enumerate() {
-                       b <<= 4;
-                       match *c {
-                               b'A'...b'F' => b |= c - b'A' + 10,
-                               b'a'...b'f' => b |= c - b'a' + 10,
-                               b'0'...b'9' => b |= c - b'0',
-                               _ => panic!("Bad hex"),
-                       }
-                       if (idx & 1) == 1 {
-                               out.push(b);
-                               b = 0;
-                       }
-               }
-       }
-
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index f2eaf0dbd41d125aa6b575527b885e4ead808a97..a2e0d3419920bfa9a00cb632dcfdc81e288ee81a 100644 (file)
@@ -35,29 +35,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
-               let mut b = 0;
-               for (idx, c) in hex.as_bytes().iter().enumerate() {
-                       b <<= 4;
-                       match *c {
-                               b'A'...b'F' => b |= c - b'A' + 10,
-                               b'a'...b'f' => b |= c - b'a' + 10,
-                               b'0'...b'9' => b |= c - b'0',
-                               _ => panic!("Bad hex"),
-                       }
-                       if (idx & 1) == 1 {
-                               out.push(b);
-                               b = 0;
-                       }
-               }
-       }
-
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 9843b79a23665303b7576e02b6d8112badcf7196..a61420db70a933cdfb25bf440336202f963a5c68 100644 (file)
@@ -35,29 +35,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
-               let mut b = 0;
-               for (idx, c) in hex.as_bytes().iter().enumerate() {
-                       b <<= 4;
-                       match *c {
-                               b'A'...b'F' => b |= c - b'A' + 10,
-                               b'a'...b'f' => b |= c - b'a' + 10,
-                               b'0'...b'9' => b |= c - b'0',
-                               _ => panic!("Bad hex"),
-                       }
-                       if (idx & 1) == 1 {
-                               out.push(b);
-                               b = 0;
-                       }
-               }
-       }
-
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index a0e9cc4efb511240f632b2e1c260ebc288d4c792..9e4b7642fc5e61bfcea9b1fee9c462c97ab5fb2a 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index dc9c2acd125859784da7c1081655c704ede341e7..09ad367e258136eb17021df623f7437335cde356 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 621ffe2b18d70bfa6157a35f0ffc33c6c25d45df..7c87970ae7c81e3035116fdc3d56755794d7d950 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index e73696c8d3801e9805d32ee28ca8fd3499cb29a5..1ded2cfe32466bfa1148b6c00978b20e9e0b7a67 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 7022786f4d5b1eb64520b22d6cb4f77094039ca1..8fa7de518a17f0717e094cdea9f62e80bc7a543d 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index f7d1a58a5e930ef3c3cfb4593754a46b877f837c..45c7c408ecc7671195f2d4d43918392e2c0b6797 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 00fdef3f82d572fd139ccad7f4025643d5a55368..e9e6fec550123f45631456d7fe976537beb35a9a 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 9b66c88fefeae67aa35710114923176e0da7d7f6..a92e2fabb75348cbc0f2f85d1964c59444782cc9 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 8d7664f8ac5bfc7cfb07b1f0441d6469766f92e1..7c1d6f8296bc74c82cf60823f94e2a07f093e99f 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index de7e9314118b265612590051bf7358c29818e0ef..560e05b02cf21a601d2bac0d9a783a443a4e41a6 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 57e245676d935763742607fee194a338c5d616b4..5df8a38254db41b78fb1fc934adab07ad55100ac 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 55a9761c9d611127c261b68bba4cd72ec0243a25..f65e91f598c3d6f9bcf616a93f08e33932784a09 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 2a2c80701cb98232ba054a1452454178746dd41f..93cdaa42c9ba6b093265d42e0fc14cc5a0c54448 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index aca62f7bb4bf9dd343f80b38f3f5596e939a97ad..ffac12184fe242d533f5474856e3f2e568ba18d1 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index e91bb3bdfd1a832d3a581df22a26622f2e57c06c..9c90992593ebe4a1fb3162dd9e3e0a78180d6c11 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index e7488306b16e98a9961371901b295237ea01bae8..4aa727126fab108e7b1be382c4358a2266391c67 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index cd449908a1736faad13884d41c8cd516fd74ecd4..86e99f8c4a0542fbcb8fad9d4deb1c8fdf3c2d6e 100644 (file)
@@ -36,13 +36,11 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       use utils::extend_vec_from_hex;
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }
index 4d355585da5d18d42dceaabdd8188953e038c3f8..27de871dcb647afc98e4dece02d28aa889d1fb7c 100644 (file)
@@ -11,22 +11,3 @@ macro_rules! test_msg {
                }
        }
 }
-
-#[allow(dead_code)]
-#[cfg(test)]
-pub fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
-       let mut b = 0;
-       for (idx, c) in hex.as_bytes().iter().enumerate() {
-               b <<= 4;
-               match *c {
-                       b'A'...b'F' => b |= c - b'A' + 10,
-                       b'a'...b'f' => b |= c - b'a' + 10,
-                       b'0'...b'9' => b |= c - b'0',
-                       _ => panic!("Bad hex"),
-               }
-               if (idx & 1) == 1 {
-                       out.push(b);
-                       b = 0;
-               }
-       }
-}
index 06d00c2ecfbe9a7abc7e7239b5d2166dc16a907e..4133331a7ebeb6d22c68e0f6fc6982caf2ac814e 100644 (file)
@@ -99,29 +99,12 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
-               let mut b = 0;
-               for (idx, c) in hex.as_bytes().iter().enumerate() {
-                       b <<= 4;
-                       match *c {
-                               b'A'...b'F' => b |= c - b'A' + 10,
-                               b'a'...b'f' => b |= c - b'a' + 10,
-                               b'0'...b'9' => b |= c - b'0',
-                               _ => panic!("Bad hex"),
-                       }
-                       if (idx & 1) == 1 {
-                               out.push(b);
-                               b = 0;
-                       }
-               }
-       }
 
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("01", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("01").unwrap());
        }
 }
index 13733adb6dfe96ed8721b2006f9d7d35bc377ff1..ed4737221670c051df8f09a7295f6811bd3792e5 100644 (file)
@@ -191,29 +191,12 @@ fn main() {
        }
 }
 
+extern crate hex;
 #[cfg(test)]
 mod tests {
-       fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
-               let mut b = 0;
-               for (idx, c) in hex.as_bytes().iter().enumerate() {
-                       b <<= 4;
-                       match *c {
-                               b'A'...b'F' => b |= c - b'A' + 10,
-                               b'a'...b'f' => b |= c - b'a' + 10,
-                               b'0'...b'9' => b |= c - b'0',
-                               _ => panic!("Bad hex"),
-                       }
-                       if (idx & 1) == 1 {
-                               out.push(b);
-                               b = 0;
-                       }
-               }
-       }
 
        #[test]
        fn duplicate_crash() {
-               let mut a = Vec::new();
-               extend_vec_from_hex("00", &mut a);
-               super::do_test(&a);
+               super::do_test(&::hex::decode("00").unwrap());
        }
 }