Skip to content

refactor(kms): split create_key / encrypt / verify / create_alias#352

Merged
vieiralucas merged 1 commit intomainfrom
worktree-cleanup-kms-long-fns
Apr 13, 2026
Merged

refactor(kms): split create_key / encrypt / verify / create_alias#352
vieiralucas merged 1 commit intomainfrom
worktree-cleanup-kms-long-fns

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 13, 2026

Summary

Apply the same `*Input::from_body` + per-phase helper pattern that PRs #329 (RDS) and #347 (RDS) used, to the four long KMS functions.

  • `create_key`: extract `CreateKeyInput::from_body` for the 30-line parse + validate block (length checks, enum checks, key-spec validation, tag parsing). The remainder reads as state-mutation phases.
  • `encrypt`: extract `decode_plaintext` (length validation 1..=4096) and `build_encrypt_ciphertext` (the imported-material XOR vs. fakecloud envelope branch).
  • `verify`: extract `require_non_empty_b64` (shared by Message + Signature), `validate_key_usage_signing`, and `validate_signing_algorithm`.
  • `create_alias`: extract `validate_alias_name` (prefix / reserved `aws/` / invalid characters / regex pattern) and `validate_alias_target` (alias-of-alias rejection); add a shared `require_string_field` for the AliasName/TargetKeyId required-string boilerplate.

Test plan

  • `cargo fmt`
  • `cargo clippy --workspace --all-targets -- -D warnings`
  • `cargo test -p fakecloud-kms --lib` — 50 passed
  • `cargo test --workspace --exclude fakecloud-e2e --exclude fakecloud-conformance`

Summary by cubic

Refactored KMS handlers to split long functions into small, focused helpers for clearer flow and reuse, with no behavior changes. Affects create_key, encrypt, verify, and create_alias in crates/fakecloud-kms/src/service.rs.

  • Refactors
    • create_key: added CreateKeyInput::from_body for parse/validate (lengths, enums, key-spec, tags); remaining code focuses on state changes.
    • encrypt: added decode_plaintext (1..=4096 bytes) and build_encrypt_ciphertext (imported-material XOR vs. fake envelope).
    • verify: added require_non_empty_b64, validate_key_usage_signing, validate_signing_algorithm.
    • create_alias: added require_string_field, validate_alias_name (prefix/reserved/regex), validate_alias_target (no alias-of-alias).
    • Centralizes validation logic; keeps error messages and behavior unchanged.

Written for commit 18cb646. Summary will update on new commits.

- create_key: extract CreateKeyInput::from_body for the 30-line parse +
  validate block (length checks, enum checks, key-spec validation, tag
  parsing). The remainder of create_key reads as state-mutation phases.
- encrypt: extract decode_plaintext (length validation 1..=4096) and
  build_encrypt_ciphertext (the imported-material XOR vs. fakecloud
  envelope branch).
- verify: extract require_non_empty_b64 (shared by Message + Signature),
  validate_key_usage_signing, and validate_signing_algorithm.
- create_alias: extract validate_alias_name (prefix, reserved aws/,
  invalid characters, regex pattern) and validate_alias_target
  (alias-of-alias rejection); add a shared require_string_field helper
  for the AliasName/TargetKeyId required-string boilerplate.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@vieiralucas vieiralucas merged commit c59a6ea into main Apr 13, 2026
22 checks passed
@vieiralucas vieiralucas deleted the worktree-cleanup-kms-long-fns branch April 13, 2026 14:33
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