Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redact #504

Merged
merged 1 commit into from
Oct 10, 2024
Merged

feat: redact #504

merged 1 commit into from
Oct 10, 2024

Conversation

zxch3n
Copy link
Member

@zxch3n zxch3n commented Oct 9, 2024

Redacts sensitive content within the specified version range by replacing it with default values.

Resolve #388

This method applies the following redaction rules:

  • Preserves delete and move operations without changes
  • Replaces text insertion content with the Unicode replacement character (U+FFFD)
  • Substitutes list and map insert values with LoroValue::Null
  • Maintains child container creation operations
  • Replaces text mark values with LoroValue::Null
  • Preserves map insertion and text annotation keys
  • Resets counter operations to zero
  • Leaves unknown operation types (from future Loro versions) unchanged

This approach ensures sensitive data removal while preserving the document's overall
structure. Redacted documents maintain seamless collaboration capabilities with both
redacted and non-redacted versions.

Example

    let doc = LoroDoc::new();
    doc.set_peer_id(1).unwrap();
    let text = doc.get_text("text");
    //              |-----------------------| <- 24 ops
    text.insert(0, "Hello, world! This is a secret message.")
        .unwrap();

    let mut json = doc.export_json_updates(&Default::default(), &doc.oplog_vv());
    let mut range = VersionRange::new();
    range.insert(1, 24, 30);
    redact(&mut json, range).unwrap();
    let redacted_doc = LoroDoc::new();
    redacted_doc.import_json_updates(json).unwrap();
    let redacted_text = redacted_doc.get_text("text");
    assert_eq!(
        redacted_text.to_string(),
        "Hello, world! This is a ������ message."
    );
    assert_ne!(text.to_string(), redacted_text.to_string());

@zxch3n zxch3n requested a review from Leeeon233 October 9, 2024 15:57
@zxch3n zxch3n self-assigned this Oct 9, 2024
@zxch3n zxch3n added the enhancement New feature or request label Oct 9, 2024
@zxch3n zxch3n merged commit f2365a8 into dev Oct 10, 2024
1 check passed
@zxch3n zxch3n deleted the zxch3n/loro-988-redact branch October 10, 2024 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants