Skip to content

Commit

Permalink
Refactor EncryptAlgorithmMetaData (#30174)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Feb 18, 2024
1 parent 33ec6a8 commit c778777
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public final class TestQueryAssistedShardingEncryptAlgorithm implements EncryptA
@Override
public void init(final Properties props) {
this.properties = props;
EncryptAlgorithmMetaData algorithmMetaData = new EncryptAlgorithmMetaData();
algorithmMetaData.setSupportDecrypt(false);
EncryptAlgorithmMetaData algorithmMetaData = new EncryptAlgorithmMetaData(false, true, false);
metaData = algorithmMetaData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@
package org.apache.shardingsphere.encrypt.spi;

import lombok.Getter;
import lombok.Setter;
import lombok.RequiredArgsConstructor;

/**
* Encrypt algorithm meta data.
*/
@RequiredArgsConstructor
@Getter
public final class EncryptAlgorithmMetaData {

@Setter
private boolean supportDecrypt = true;
private final boolean supportDecrypt;

@Setter
private boolean supportEquivalentFilter = true;
private final boolean supportEquivalentFilter;

@Setter
private boolean supportLike;
private final boolean supportLike;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public final class MD5AssistedEncryptAlgorithm implements EncryptAlgorithm {
@Override
public void init(final Properties props) {
this.salt = props.getProperty(SALT_KEY, "");
EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData();
encryptAlgorithmMetaData.setSupportDecrypt(false);
metaData = encryptAlgorithmMetaData;
metaData = new EncryptAlgorithmMetaData(false, true, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class AESEncryptAlgorithm implements EncryptAlgorithm {

@Override
public void init(final Properties props) {
metaData = new EncryptAlgorithmMetaData();
metaData = new EncryptAlgorithmMetaData(true, true, false);
secretKey = createSecretKey(props);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Getter
public final class CoreEncryptAlgorithmFixture implements EncryptAlgorithm {

private final EncryptAlgorithmMetaData metaData = new EncryptAlgorithmMetaData();
private final EncryptAlgorithmMetaData metaData = new EncryptAlgorithmMetaData(true, true, false);

@Override
public String encrypt(final Object plainValue, final EncryptContext encryptContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public final class CoreQueryAssistedEncryptAlgorithmFixture implements EncryptAl

@Override
public void init(final Properties props) {
EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData();
encryptAlgorithmMetaData.setSupportDecrypt(false);
metaData = encryptAlgorithmMetaData;
metaData = new EncryptAlgorithmMetaData(false, true, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ public final class CoreQueryLikeEncryptAlgorithmFixture implements EncryptAlgori

@Override
public void init(final Properties props) {
EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData();
encryptAlgorithmMetaData.setSupportLike(true);
encryptAlgorithmMetaData.setSupportDecrypt(false);
encryptAlgorithmMetaData.setSupportEquivalentFilter(false);
metaData = encryptAlgorithmMetaData;
metaData = new EncryptAlgorithmMetaData(false, false, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Getter
public final class DistSQLEncryptAlgorithmFixture implements EncryptAlgorithm {

private final EncryptAlgorithmMetaData metaData = new EncryptAlgorithmMetaData();
private final EncryptAlgorithmMetaData metaData = new EncryptAlgorithmMetaData(true, true, false);

@Override
public String encrypt(final Object plainValue, final EncryptContext encryptContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Getter
public final class JDBCEncryptAlgorithmFixture implements EncryptAlgorithm {

private final EncryptAlgorithmMetaData metaData = new EncryptAlgorithmMetaData();
private final EncryptAlgorithmMetaData metaData = new EncryptAlgorithmMetaData(true, true, false);

@Override
public String encrypt(final Object plainValue, final EncryptContext encryptContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public final class JDBCQueryAssistedEncryptAlgorithmFixture implements EncryptAl

@Override
public void init(final Properties props) {
EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData();
encryptAlgorithmMetaData.setSupportDecrypt(false);
metaData = encryptAlgorithmMetaData;
metaData = new EncryptAlgorithmMetaData(false, true, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ public void init(final Properties props) {
mask = createMask(props);
start = createStart(props);
charIndexes = createCharIndexes(props);
EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData();
encryptAlgorithmMetaData.setSupportLike(true);
encryptAlgorithmMetaData.setSupportDecrypt(false);
metaData = encryptAlgorithmMetaData;
metaData = new EncryptAlgorithmMetaData(false, true, true);
}

private int createDelta(final Properties props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Getter
public final class RewriteNormalEncryptAlgorithmFixture implements EncryptAlgorithm {

private final EncryptAlgorithmMetaData metaData = new EncryptAlgorithmMetaData();
private final EncryptAlgorithmMetaData metaData = new EncryptAlgorithmMetaData(true, true, false);

@Override
public String encrypt(final Object plainValue, final EncryptContext encryptContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public final class RewriteQueryAssistedEncryptAlgorithmFixture implements Encryp

@Override
public void init(final Properties props) {
EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData();
encryptAlgorithmMetaData.setSupportDecrypt(false);
metaData = encryptAlgorithmMetaData;
metaData = new EncryptAlgorithmMetaData(false, true, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public final class RewriteQueryLikeEncryptAlgorithmFixture implements EncryptAlg

@Override
public void init(final Properties props) {
EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData();
encryptAlgorithmMetaData.setSupportLike(true);
encryptAlgorithmMetaData.setSupportDecrypt(false);
metaData = encryptAlgorithmMetaData;
metaData = new EncryptAlgorithmMetaData(false, true, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public final class TestQueryAssistedShardingEncryptAlgorithm implements EncryptA
@Override
public void init(final Properties props) {
this.properties = props;
EncryptAlgorithmMetaData encryptAlgorithmMetaData = new EncryptAlgorithmMetaData();
encryptAlgorithmMetaData.setSupportDecrypt(false);
metaData = encryptAlgorithmMetaData;
metaData = new EncryptAlgorithmMetaData(false, true, false);
}

@Override
Expand Down

0 comments on commit c778777

Please sign in to comment.