Skip to content

refactor(convert): make the Backend trait fully IR-native - #363

Merged
mostafa merged 5 commits into
mainfrom
feat/convert-ir-render
Jul 20, 2026
Merged

refactor(convert): make the Backend trait fully IR-native#363
mostafa merged 5 commits into
mainfrom
feat/convert-ir-render

Conversation

@mostafa

@mostafa mostafa commented Jul 20, 2026

Copy link
Copy Markdown
Member

Routes rsigma-convert entirely through the intermediate representation. A rule is lowered to IrRule once, both the detection and condition walks run over the HIR, and the Backend trait's value leaves consume the faithful matcher model with no parser types.

What changed

  • The Backend trait is parser-free. Value leaves are IR-native:
    • convert_field_str(field, IrStrOp, &IrPattern, case_insensitive) over a wildcard-aware, original-case pattern
    • convert_field_regex(field, pattern, RegexFlags)
    • convert_field_compare_op(field, CompareOp, value)
    • convert_keyword_str(&IrPattern) / convert_keyword_num(f64)
    • the already-parser-free convert_field_eq_num / eq_bool / eq_null / eq_cidr, convert_field_exists, convert_field_eq_query_expr, convert_field_ref
  • Detection and condition dispatch walk IrDetection / IrCondition via convert_ir_detection / convert_ir_detection_item. PostgreSQL keeps its JSONB array-match override and Fibratus keeps its multi-value re / cidr / string-list collapse, both ported to IrMatcher.
  • Removed the dead parser dispatch: condition.rs, the default_convert_detection / default_convert_detection_item helpers and their multi-value paths, and the SigmaString-based text_convert_value_str / text_convert_field_eq_str free helpers.

Compatibility

PostgreSQL, LynxDB, and Fibratus golden outputs are byte-identical. Full suite (3086 tests) passes; clippy --all-targets --all-features -D warnings, fmt --check, cargo doc, and the docs site build/validate are green.

Builds on #360 and #362.

xref #346

mostafa added 5 commits July 20, 2026 22:14
Port text_convert_value_str / text_convert_field_eq_str to read the
faithful IrPattern (wildcard-aware, original case) and an explicit IrStrOp
instead of a parser SigmaString + modifier slice. These are the rendering
building blocks for the IR-native Backend leaves; the wiring follows.
Add convert_field_str/num/bool/null/regex/cidr/compare_op and
convert_keyword_str/num consuming IrPattern/IrStrOp/CompareOp with no parser
types. Default impls reconstruct the equivalent SigmaString/modifiers and
delegate to the existing parser-typed leaves, so every backend is IR-native
for free (byte-identical); backends override these next to drop the parser
dependency.
convert_rule now lowers the whole rule to HIR and converts detections,
items, keywords, array matches, and conditional blocks from the faithful IR
(ir_convert dispatch on IrMatcher). PostgreSQL JSONB array matching and
Fibratus's list/regex/cidr collapse are ported to IR natively; value
rendering delegates to the existing leaves via the default IR-native leaf
impls, so PG/LynxDB/Fibratus goldens stay byte-identical. Adds IrMatcher::
Regex.cased so backends can pick a case-sensitive regex operator (eval
ignores it), and maps IR lowering errors to the historical convert error
kinds.
Remove every parser-typed method from the Backend trait and its
implementations. Detection and condition walks run over the lowered
IrRule, and value leaves consume the faithful HIR: convert_field_str
over IrStrOp + wildcard-aware IrPattern, convert_field_regex with
RegexFlags, convert_field_compare_op with CompareOp, and
convert_keyword_str / convert_keyword_num. Backends render from the
pattern directly, so none of them touch rsigma-parser to emit a value
match.

Drop the now-dead parser dispatch (condition.rs, the default_convert_*
helpers) and the SigmaString-based text helpers. PostgreSQL, LynxDB,
and Fibratus golden outputs stay byte-identical.
@mostafa
mostafa merged commit 2bc43d8 into main Jul 20, 2026
16 checks passed
@mostafa
mostafa deleted the feat/convert-ir-render branch July 20, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant