Echo-Community-Toolkit-Monorepo

Phase 1 – Legacy Refresh

Phase 1 modernises the core LSB extractor while preserving backwards compatibility with archived payloads. The goal is to yield a clean separation between modern LSB1 headers and historic null-terminated streams, backed by a regression suite that guarantees the golden sample continues to decode.

Objectives

Implementation Plan

  1. Parser separation
    • Introduce helpers such as parse_lsb1_header(data: bytes) -> Header to detect the “LSB1” magic, version, flags, payload length, and CRC32.
    • Split legacy handling into extract_legacy_payload(bits: Iterable[int]) -> bytes, retaining the null-terminated parsing logic.
    • Provide a raw bit stream reader to fall back gracefully when neither header nor null terminator is detected.
    • Update LSBExtractor to orchestrate the parsers and return structured decode results (payload, mode, metadata, crc status).
  2. Robust validation
    • Validate header lengths, flag combinations, and CRC/length before attempting decode.
    • Trap Base64 errors explicitly; surface a DecodeError that contains the failing step (crc_mismatch, invalid_base64, etc.).
    • Ensure CRC mismatches abort the decode path and never return best-effort plaintext.
  3. Surface metadata
    • Preserve header metadata (flags, version, bits-per-channel) so downstream tooling can make mode decisions in Phase 2.
    • Map flag bits to symbolic names and document them in the README/Phase docs.

Testing Strategy

Dependencies & Hand-offs

Risks & Mitigations