Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption predicate #71

Merged
merged 4 commits into from
Apr 26, 2024
Merged

Conversation

basz
Copy link
Contributor

@basz basz commented Apr 17, 2024

#70

I think it is a simple as this... Let me know if see see any issues...

@basz
Copy link
Contributor Author

basz commented Apr 17, 2024

first issue is see is that this can't work with the EncryptionTransformer if i'm not mistaking. That does not have access to the entity so it cant call the predicate function. Does someone see way around that?

src/entity.ts Outdated
@@ -14,6 +14,9 @@ export function encrypt<T extends ObjectLiteral>(entity: any): any {
let { propertyName, mode, target } = columnMetadata;
let options: ExtendedColumnOptions = columnMetadata.options;
let encrypt = options.encrypt;
if (encrypt?.encryptionPredicate && !encrypt?.encryptionPredicate(entity)) {
Copy link
Owner

@generalpiston generalpiston Apr 17, 2024

Choose a reason for hiding this comment

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

can you merge this with let encrypt = options.encrypt above or with the condition below?

src/entity.ts Outdated
@@ -42,6 +45,9 @@ export function decrypt<T extends ObjectLiteral>(entity: any): any {
let { propertyName, mode, target } = columnMetadata;
let options: ExtendedColumnOptions = columnMetadata.options;
let encrypt = options.encrypt;
if (encrypt?.encryptionPredicate && !encrypt?.encryptionPredicate(entity)) {
Copy link
Owner

Choose a reason for hiding this comment

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

can you merge this with let encrypt = options.encrypt above or with the condition below?

@@ -5,4 +5,5 @@ export interface EncryptionOptions {
iv?: string; //// For testing mainly.
authTagLength?: number;
looseMatching?: boolean;
encryptionPredicate?: (entity: any) => boolean;
Copy link
Owner

Choose a reason for hiding this comment

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

maybe change to shouldEncrypt and let it be a function or boolean value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I (respectfully) think we should not do that...

Because the term predicate implies a callable on a condition. shouldEncrypt with dual a usage (bool and a callback) as you propose would be less clear and complicates the if checks in the entity class. Lastly the whole intent is it should resolve to a boolean based on some condition. The condition should not be a hardcode false as that simply turn off encryption on column as a whole, and then why would a user use the encrypt at in the first place.

Unless you disagree with this of course I'm happy to make the change.

Copy link
Owner

@generalpiston generalpiston left a comment

Choose a reason for hiding this comment

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

A few nits... looks really good!

@basz
Copy link
Contributor Author

basz commented Apr 22, 2024

@generalpiston hello.

Did you/do you have time to do an other review maybe this week?

@generalpiston
Copy link
Owner

Good stuff! I should be able to run a release this weekend.

@generalpiston generalpiston merged commit c8ea1ac into generalpiston:master Apr 26, 2024
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