Skip to content

Return false from the composite's Try methods when a stage fails - #42

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/composite-try-returns-false
Sep 26, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/composite-try-returns-false

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #40

What changed

CompositeObfuscationProvider passed data to each stage through the throwing Obfuscate/Deobfuscate convenience methods. If a stage rejected its input, the composite's Try* methods threw InvalidOperationException instead of returning false. Base64 and Hex both reject invalid data this way.

The four Try* overloads (span and stream, obfuscate and deobfuscate) now go through two private helpers, TryRunForward and TryRunReverse. These helpers:

  • call each stage's own TryObfuscate/TryDeobfuscate
  • size each intermediate buffer from that stage's GetMaxObfuscatedLength/GetMaxDeobfuscatedLength
  • stop and return false as soon as a stage fails

When a stage fails, the stream overloads write nothing to the destination.

Tests

  • New tests use an Xor + Base64 composite, where the Base64 stage can fail:
    • Obfuscation_Composite_TryDeobfuscate_Span_ReturnsFalseWhenAStageFails
    • Obfuscation_Composite_TryDeobfuscate_Stream_ReturnsFalseWhenAStageFails
    • Obfuscation_Composite_WithFallibleStage_Roundtrips, which checks that a successful round trip still works through the new path
  • With the fix reverted, both ReturnsFalse tests fail.
  • Full suite passes: 907/907.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NHprKRwyYopkJnUyhF3KSr


Generated by Claude Code

CompositeObfuscationProvider ran each stage through the throwing
Obfuscate/Deobfuscate convenience methods, so a stage that rejects its
input (Base64 or Hex fed invalid data) made the composite's Try methods
throw InvalidOperationException instead of returning false. The stages
now chain through their own Try methods, with each intermediate buffer
sized from the stage's GetMax*Length, and the composite returns false as
soon as one fails.

Fixes #40

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NHprKRwyYopkJnUyhF3KSr
@sonarqubecloud

Copy link
Copy Markdown

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.

CompositeObfuscationProvider.TryDeobfuscate throws InvalidOperationException on invalid input instead of returning false

2 participants