qubit-redact 0.3.0

Rule-driven redaction for fields, diagnostics, HTTP data, and Rust domain objects
Documentation
qubit-redact-0.3.0 has been yanked.

Qubit Redact

Rust CI Coverage Crates.io Rust License 中文文档

Qubit Redact prevents sensitive values from leaking through Rust diagnostics: logs, Debug output, process arguments, environment variables, and optional HTTP traces. Define immutable policies once, then render typed results at an explicit log-safe boundary.

Why Qubit Redact

  • One policy model classifies named fields across scalar values, maps, domain objects, process diagnostics, and optional HTTP data.
  • Typed results distinguish redacted values from text that is safe to write to a plain-text log.
  • Malformed or truncated structured HTTP input fails closed, and diagnostic budgets bound inspection, output, and disclosure.
  • The default feature set is empty; the core crate has no external runtime dependencies.

Quick Start

[dependencies]
qubit-redact = "0.3"
use qubit_redact::{RedactionPolicy, Redactor, Sensitivity};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let policy = RedactionPolicy::builder()
        .raise("user_id", Sensitivity::Low)
        .raise("phone_number", Sensitivity::Medium)
        .raise("credit_card", Sensitivity::High)
        .raise("api_key", Sensitivity::Secret)
        .build()?;
    let redactor = Redactor::new(policy);

    assert_eq!(redactor.redact("user_id", "alpine42").as_str(), "al****42");
    assert_eq!(redactor.redact("phone_number", "13800138000").as_str(), "*******0");
    assert_eq!(redactor.redact("credit_card", "4111111111111111").as_str(), "****");
    assert_eq!(redactor.redact("api_key", "sk_live_123").as_str(), "<redacted>");

    let safe = redactor
        .redact("display_name", "Alice\nAdmin")
        .escape_for_log();
    assert_eq!(safe.to_string(), "Alice\\nAdmin");
    Ok(())
}

The original value remains available to application logic. Call escape_for_log() before writing a scalar result to a plain-text log sink.

Choose a Tool

Diagnostic input Tool Result and logging boundary
Named scalar value Redactor::redact RedactedText; call escape_for_log() for plain-text logs.
Text-keyed map Redactor::redact_map or redact_map_in_place A copied or mutated map; apply the final logging format yourself.
Rust struct or enum Redact derive Borrowed Redacted<T> view with safe formatting.
Value that must be logically replaced RedactMut derive Mutated value; this is not memory erasure.
Command arguments ArgvRedactor RedactedArgv, safe to display.
Environment pairs EnvRedactor RedactedEnvPair or LogSafeText.
URL, form, headers, or captured body HttpRedactor Bounded, log-safe HTTP result types.

Cargo Features

Need Cargo configuration
Core scalar, map, process, and text support qubit-redact = "0.3"
Domain-object derives Add qubit-redact-derive = "0.3".
Serialize redacted views Enable serde and declare serde directly.
Redact serde_json::Value or JSON text fields Enable json; add serde_json directly when your application uses it.
HTTP diagnostics Enable http; add http directly when your application uses its types.
[dependencies]
# HTTP diagnostics only
qubit-redact = { version = "0.3", features = ["http"] }
http = "1.4"

Safety Boundaries

  • Unknown field names pass through by default. Set UnknownFieldPolicy::Redact(Sensitivity::Secret) when a boundary must mask every unclassified field; classify_field() still reports Unknown.
  • Allow rules intentionally win and can disclose data. Prefer exact allow rules and treat each one as a security decision.
  • RedactedText is not displayable by design. Redaction and log escaping are separate guarantees.
  • RedactMut replaces logical values only. It does not erase released allocations, aliases, copies, or borrowed backing storage.
  • HTTP redaction accepts only caller-provided captures. It never reads or buffers a network body itself.

Learn More

Testing

# Run tests with the default feature set
cargo test

# Run tests with all declared features
cargo test --all-features

# Project CI checks
./ci-check.sh

# Check code coverage
./coverage.sh

License

Copyright (c) 2025 - 2026. Haixing Hu. All rights reserved.

Licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Contributing

Contributions are welcome. Please follow the Rust API guidelines, keep public API documentation and tests current, and run ./align-ci.sh to format code and ./ci-check.sh to satisfy CI requirements before submitting a pull request.

Author

Haixing Hu - Qubit Co. Ltd.

Repository: https://github.com/qubit-ltd/rs-redact