Skip to content

feat(encryption): add a shared Encryption service over the framework Encryptor#713

Merged
aryanjasala merged 4 commits into
theme-elementary-v2from
refactor/encryptor-instance
Jun 11, 2026
Merged

feat(encryption): add a shared Encryption service over the framework Encryptor#713
aryanjasala merged 4 commits into
theme-elementary-v2from
refactor/encryptor-instance

Conversation

@aryanjasala

@aryanjasala aryanjasala commented Jun 11, 2026

Copy link
Copy Markdown
Member

What this does

Wires the theme into the framework's instance-based Encryptor, following the
same consumer pattern as Assets / Components / Templates: a context-owned
Core service shared through the container, with Util wrappers as the call
surface.

Changes

  • Add inc/Core/Encryption.phpfinal class Encryption extends Encryptor implements Shareable; overrides the key() seam to source the key from the
    ELEMENTARY_ENCRYPTION_KEY constant. No salt fallback — without the constant
    the framework's parent::key() throws on first use.
  • inc/Main.php — register Encryption in CLASSES.
  • inc/Helpers/Util.phpUtil::encrypt() / Util::decrypt() backed by a
    shared encryptor() resolved via get_shared( Encryption::class ).

Configuration

Define a dedicated key in wp-config.php before first use:

define( 'ELEMENTARY_ENCRYPTION_KEY', '<32+ bytes of random data>' );

There is deliberately no LOGGED_IN_KEY fallback: an auth salt should not
double as an encryption key, and rotating WordPress salts (standard incident
response) must never invalidate encrypted data. The throw is lazy — boot and
container registration never error; only an actual Util::encrypt() /
Util::decrypt() call without the constant does.

How I verified

  • php -l clean on changed files.
  • Smoke test (framework branch symlinked): Encryption extends Encryptor, is
    Shareable; without the constant the first encrypt throws the framework's
    RuntimeException; with the constant a full encrypt → decrypt roundtrip
    succeeds.

Reviewer notes

  • Stacks on the framework Encryptor PR; bump composer.lock once it lands on
    main.

…Encryptor

Extend the framework Encryptor with a key() override that sources the key
from a project constant — no salt fallback; without the constant the
framework refuses to encrypt. Shared through the container like the other
loaders, with Util::encrypt()/decrypt() wrappers.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a shared theme-level encryption service built on the framework Encryptor, registers it in the theme bootstrap, and exposes encryption/decryption via Helpers\Util for consistent consumption across the theme.

Changes:

  • Added inc/Core/Encryption.php as a shared (container-managed) encryptor service sourcing its key from ELEMENTARY_ENCRYPTION_KEY.
  • Registered the new Encryption service in Main::CLASSES so it’s loaded by the theme bootstrap.
  • Added Util::encrypt() / Util::decrypt() wrappers that resolve and delegate to the shared Encryption instance.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
inc/Main.php Registers the new Core\Encryption service in the theme’s load list.
inc/Helpers/Util.php Adds encrypt()/decrypt() wrappers backed by the shared encryptor instance.
inc/Core/Encryption.php Implements the shared encryptor service and overrides key resolution via ELEMENTARY_ENCRYPTION_KEY.

Comment thread inc/Helpers/Util.php
Comment thread inc/Helpers/Util.php
Comment thread inc/Helpers/Util.php
…or/encryptor-instance

# Conflicts:
#	inc/Helpers/Util.php
#	inc/Main.php
… path

Add EncryptionTest (wiring, missing-key throw, Util roundtrip, tamper
detection) and @throws tags on Util::encrypt()/decrypt(); widen the key()
@throws wording to cover an empty constant.
Refresh composer.lock: rtcamp/wp-framework dev-main → 2e8fa2d, the main tip
carrying the injectable Encryptor that Core\Encryption extends.
@aryanjasala aryanjasala merged commit 9149001 into theme-elementary-v2 Jun 11, 2026
8 checks passed
@aryanjasala aryanjasala deleted the refactor/encryptor-instance branch June 11, 2026 23:07
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.

3 participants