Skip to content

Conversation

innocenzi
Copy link
Member

This pull request adds support for a new #[Hashed] and #[Encrypted] attributes, expected to be used on database models.

final class User
{
    public PrimaryKey $id;

    public string $email;

    #[Hashed]
    public ?string $password;

    #[Encrypted]
    public ?string $accessToken;
}

To ease their implementation, I came up with a new ProvidesCaster and ProvidesSerializer interfaces. These interfaces can be implemented by attributes, which may provide specific serializers and casters.

#[Attribute(Attribute::TARGET_PROPERTY)]
final class Hashed implements ProvidesSerializer
{
    public string $serializer {
        get => HashedSerializer::class;
    }
}

#[Attribute(Attribute::TARGET_PROPERTY)]
final class Encrypted implements ProvidesSerializer, ProvidesCaster
{
    public string $serializer {
        get => EncryptedSerializer::class;
    }

    public string $caster {
        get => EncryptedCaster::class;
    }
}

This is an alternative to #[CastWith] and #[SerializeWith], but they are still useful—their purpose is just slightly different.

brendt
brendt previously requested changes Aug 20, 2025
Copy link
Member

@brendt brendt left a comment

Choose a reason for hiding this comment

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

I like it!

I have one remark, and was also wondering if you could add the docs for it within this PR?

@innocenzi innocenzi force-pushed the feat/encryption-attributes branch from 7c5c84a to beb2fd0 Compare August 24, 2025 14:03
@innocenzi innocenzi merged commit aca1f9a into 2.x Aug 24, 2025
88 of 89 checks passed
@innocenzi innocenzi deleted the feat/encryption-attributes branch August 24, 2025 14:41
@innocenzi
Copy link
Member Author

The docs are sparse but I plan on updating the db docs anyway, since the ORM refactor

Bapawe pushed a commit to Bapawe/tempest-framework that referenced this pull request Aug 29, 2025
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.

2 participants