feat(engine): anonymize-on-export#48
Merged
Merged
Conversation
Add src/ocpp/anonymize.zig: rewrite a parsed trace to shareable pretty JSON, mirroring the toolkit's cli/commands/anonymize.ts. Replace known sensitive keys (idTag / chargePointSerialNumber / chargeBoxSerialNumber / stationId / identifier), resequence transactionIds, and redact email / phone / IPv4 patterns in string values. Zig std has no regex, so each pattern is a hand-rolled matcher applied in three sequential left-to-right passes, matching the toolkit's regex replacements. Faithfully mirror two toolkit quirks, flagged in-code rather than silently diverging: meter values are not transformed (the docstring claims otherwise), and transactionId resequences per occurrence (repeated ids get different numbers). Bound recursion depth for untrusted input; pure and headless (no file I/O). Closes #42.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
feat(engine): trace anonymization (S4 #42) — strip sensitive fields so atrace can be shared safely.
Closes #42.
Changes
src/ocpp/anonymize.zig—anonymizeToJson(value)/anonymizeJsonText(text)walk the parsed JSON and emit pretty (2-space) JSON, mirroring the toolkit's
cli/commands/anonymize.ts:idTag/identifier→"anonymized";chargePointSerialNumber/chargeBoxSerialNumber/stationId→"station-anon"; numerictransactionId→ resequenced.[redacted-email], phone →[redacted-phone],IPv4 →
[redacted-ip]. Zig std has no regex, so each is a hand-rolled matcherrun in three sequential left-to-right passes (JS global-replace semantics).
ocpp.zig; CURRENT_STATE updated.Mirroring the code, flagging the quirks
Two toolkit behaviors are reproduced deliberately and documented in-code, not
silently "fixed":
transactionIdresequences per occurrence — repeated occurrences of thesame id get different numbers, so correlation isn't preserved (matches
txCounter.next++). A stable distinct-id mapping is a possible futureenhancement.
Safety
max_depth) for untrusted, deeply-nested input.Tests
104/104 headless tests pass (
native test -Dplatform=null);native check --strictclean;zig fmtclean. New coverage: sensitive-key replacement,email/phone/IPv4 redaction, numeric meter-value preservation, per-occurrence
transactionIdresequencing, JSON round-trip through nested arrays/objects withescaping, and precise phone/IPv4 matcher boundaries.