refactor(server): introduce CryptoService, replace MasterKey DI#119
Merged
Conversation
Replace the MasterKey DI service + free crypto functions with a single CryptoService that owns the master key and exposes workspace-scoped (and master-scoped) encrypt/decrypt directly. - CryptoService loads the key file (absorbing MasterKey's loading) and derives the per-workspace key internally; handlers call one method instead of derive-then-encrypt. - The cipher functions and EncryptionKey become crate-internal; the public crypto surface is CryptoService + CryptoConfig (renamed from MasterKeyConfig) + CryptoError. - Add From<CryptoError> for the handler HTTP error so call sites use `?`, removing the repeated map_err boilerplate. - Rewire ServiceState DI (crypto replaces master_key), cli CryptoArgs, and the four connection/context call sites. Delete service/security/master_key.rs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the
MasterKeyDI service + free crypto functions with a singleCryptoServicethat handlers use directly.Before
After
Changes
CryptoServiceowns the master key (loaded from the key file, absorbingMasterKey's loading logic) and exposes workspace-scopedencrypt/decrypt/encrypt_json/decrypt_json(deriving the per-workspace key internally) plus master-scoped variants.Clonefor DI.EncryptionKeybecome crate-internal; the public crypto surface isCryptoService+CryptoConfig(renamed fromMasterKeyConfig) +CryptoError.From<CryptoError>for the handler HTTP error so call sites use?— removing the repeatedmap_errboilerplate.cryptoreplacesmaster_keyinServiceState), cliCryptoArgs, server test helper, and the four connection/context call sites updated.service/security/master_key.rsdeleted.Verification
Full workspace green:
cargo check,clippy -D warnings,cargo +nightly fmt --check,cargo doc -D warnings,cargo deny check all, tests (incl. 4 new CryptoService tests). Server boots end-to-end and loads the key through CryptoService.🤖 Generated with Claude Code