Skip to content

feat(vault): add OFV1 magic byte header to vault files#28

Open
mduongvandinh wants to merge 1 commit intoRightNow-AI:mainfrom
mduongvandinh:feat/vault-magic-bytes
Open

feat(vault): add OFV1 magic byte header to vault files#28
mduongvandinh wants to merge 1 commit intoRightNow-AI:mainfrom
mduongvandinh:feat/vault-magic-bytes

Conversation

@mduongvandinh
Copy link

Summary

  • Add 4-byte magic header (OFV1) to vault file format for fast format detection and corruption checking
  • Backward compatible: legacy JSON-only vault files (no magic prefix) still load correctly

Changes

  • save(): prepend OFV1 bytes before JSON content
  • load(): 3-way format detection — OFV1 prefix / legacy JSON / reject unrecognized
  • Remove #[allow(dead_code)] from VAULT_MAGIC constant (now actively used)
  • Add 3 new tests: magic bytes present, wrong magic rejected, legacy backward compat

Test plan

  • All 7 vault tests pass (cargo test -p openfang-extensions vault)
  • Clippy clean
  • Existing vault_init_and_roundtrip test confirms full encrypt/save/load/decrypt cycle works with new format

Files changed

  • crates/openfang-extensions/src/vault.rs (+109, -4)

Prepend 4-byte magic header (OFV1) when saving vault files.
Validate header on load, with backward compat for legacy JSON-only
format (files starting with '{' are accepted as-is). Enables fast
format detection and corruption checking.
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.

1 participant