fuzz_htlc_witness.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #![no_main]
  2. use libfuzzer_sys::fuzz_target;
  3. use cashu::nuts::nut14::HTLCWitness;
  4. fuzz_target!(|data: &str| {
  5. // Fuzz HTLCWitness JSON deserialization
  6. // This tests the preimage and signatures field parsing
  7. if let Ok(witness) = serde_json::from_str::<HTLCWitness>(data) {
  8. // If we successfully parsed an HTLCWitness, fuzz the preimage_data() method
  9. // This validates:
  10. // - Hex decoding of the preimage
  11. // - Exactly 32 bytes requirement
  12. let _ = witness.preimage_data();
  13. }
  14. // Fuzz preimage_data() directly with arbitrary preimage strings
  15. // This exercises the hex validation and size checking with raw input
  16. let witness = HTLCWitness {
  17. preimage: data.to_string(),
  18. signatures: None,
  19. };
  20. let _ = witness.preimage_data();
  21. // Fuzz with signatures field populated
  22. // Test various signature list formats
  23. if let Ok(sigs) = serde_json::from_str::<Vec<String>>(data) {
  24. let witness_with_sigs = HTLCWitness {
  25. preimage: String::new(),
  26. signatures: Some(sigs),
  27. };
  28. let _ = witness_with_sigs.preimage_data();
  29. }
  30. });