Skip to content

Commit

Permalink
Implement custom serializer for wildcard-matching
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Palacios <accorell@amazon.com>
  • Loading branch information
adpaco-aws committed Mar 7, 2025
1 parent 9949731 commit c0cb75d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cedar-drt/fuzz/fuzz_targets/wildcard-matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use cedar_drt_inner::fuzz_target;
use cedar_policy_core::ast::{Pattern, PatternElem};
use libfuzzer_sys::arbitrary::{self, Arbitrary, Result, Unstructured};
use regex::{escape, Regex};
use serde::{Serialize, Serializer};
use serde::ser::SerializeStruct;

/// Input expected by this fuzz target:
/// A pattern and a string that matches it
Expand All @@ -31,6 +33,24 @@ struct FuzzTargetInput {
pub string: String,
}

impl Serialize for FuzzTargetInput {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("FuzzTargetInput", 2)?;

let pattern: Vec<String> = self.pattern.iter().map(|e| match e {
PatternElem::Char(c) => c.to_string(),
PatternElem::Wildcard => "*".to_string(),
}).collect();

state.serialize_field("pattern", &pattern)?;
state.serialize_field("string", &self.string)?;
state.end()
}
}

/// A wrapper struct for valid characters:
/// A character `c` is valid if it satisfies two criteria:
/// 1. c as u32 <= 0xffff (i.e., c is in the Basic Multilingual Plane.)
Expand Down

0 comments on commit c0cb75d

Please sign in to comment.