This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 7b60d70fd7e Refactor EncryptAlgorithm‘s impl (#30197)
7b60d70fd7e is described below
commit 7b60d70fd7e79da57be6acef829b5eac70996d39
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Feb 19 17:18:54 2024 +0800
Refactor EncryptAlgorithm‘s impl (#30197)
* Fix javadoc
* Refactor EncryptAlgorithm‘s impl
---
.../apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java | 4 ++--
.../algorithm/assisted/MD5AssistedEncryptAlgorithm.java | 5 ++---
.../encrypt/algorithm/standard/AESEncryptAlgorithm.java | 3 +--
.../fixture/CoreQueryAssistedEncryptAlgorithmFixture.java | 9 +--------
.../fixture/CoreQueryLikeEncryptAlgorithmFixture.java | 9 +--------
.../encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java | 9 +--------
.../test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java | 3 +--
.../encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java | 9 +--------
.../encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java | 9 +--------
.../algorithm/TestQueryAssistedShardingEncryptAlgorithm.java | 12 +-----------
10 files changed, 12 insertions(+), 60 deletions(-)
diff --git
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java
index c2de24d19c1..beffbfb3259 100644
---
a/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java
+++
b/features/encrypt/api/src/main/java/org/apache/shardingsphere/encrypt/spi/EncryptAlgorithm.java
@@ -44,9 +44,9 @@ public interface EncryptAlgorithm extends
ShardingSphereAlgorithm {
Object decrypt(Object cipherValue, AlgorithmSQLContext
algorithmSQLContext);
/**
- * Get meta data.
+ * Get encrypt algorithm meta data.
*
- * @return meta data.
+ * @return encrypt algorithm meta data
*/
EncryptAlgorithmMetaData getMetaData();
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
index 020f80c4d7c..4146bc12ef5 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/assisted/MD5AssistedEncryptAlgorithm.java
@@ -37,12 +37,11 @@ public final class MD5AssistedEncryptAlgorithm implements
EncryptAlgorithm {
private String salt;
@Getter
- private EncryptAlgorithmMetaData metaData;
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(false, true, false);
@Override
public void init(final Properties props) {
- this.salt = props.getProperty(SALT_KEY, "");
- metaData = new EncryptAlgorithmMetaData(false, true, false);
+ salt = props.getProperty(SALT_KEY, "");
}
@Override
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
index abc4621b55b..0526b309bb9 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/standard/AESEncryptAlgorithm.java
@@ -51,13 +51,12 @@ public final class AESEncryptAlgorithm implements
EncryptAlgorithm {
private static final String DIGEST_ALGORITHM_NAME =
"digest-algorithm-name";
@Getter
- private EncryptAlgorithmMetaData metaData;
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(true, true, false);
private byte[] secretKey;
@Override
public void init(final Properties props) {
- metaData = new EncryptAlgorithmMetaData(true, true, false);
secretKey = createSecretKey(props);
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryAssistedEncryptAlgorithmFixture.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryAssistedEncryptAlgorithmFixture.java
index 6a2764093de..d91d66573c8 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryAssistedEncryptAlgorithmFixture.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryAssistedEncryptAlgorithmFixture.java
@@ -22,17 +22,10 @@ import
org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
-import java.util.Properties;
-
@Getter
public final class CoreQueryAssistedEncryptAlgorithmFixture implements
EncryptAlgorithm {
- private EncryptAlgorithmMetaData metaData;
-
- @Override
- public void init(final Properties props) {
- metaData = new EncryptAlgorithmMetaData(false, true, false);
- }
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(false, true, false);
@Override
public String encrypt(final Object plainValue, final AlgorithmSQLContext
algorithmSQLContext) {
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryLikeEncryptAlgorithmFixture.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryLikeEncryptAlgorithmFixture.java
index 1c46a7a2ff7..6295a91591e 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryLikeEncryptAlgorithmFixture.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/fixture/CoreQueryLikeEncryptAlgorithmFixture.java
@@ -22,17 +22,10 @@ import
org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
-import java.util.Properties;
-
@Getter
public final class CoreQueryLikeEncryptAlgorithmFixture implements
EncryptAlgorithm {
- private EncryptAlgorithmMetaData metaData;
-
- @Override
- public void init(final Properties props) {
- metaData = new EncryptAlgorithmMetaData(false, false, true);
- }
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(false, false, true);
@Override
public String encrypt(final Object plainValue, final AlgorithmSQLContext
algorithmSQLContext) {
diff --git
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java
index 4c1086af818..76835ff8537 100644
---
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java
+++
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/fixture/encrypt/JDBCQueryAssistedEncryptAlgorithmFixture.java
@@ -22,17 +22,10 @@ import
org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
-import java.util.Properties;
-
@Getter
public final class JDBCQueryAssistedEncryptAlgorithmFixture implements
EncryptAlgorithm {
- private EncryptAlgorithmMetaData metaData;
-
- @Override
- public void init(final Properties props) {
- metaData = new EncryptAlgorithmMetaData(false, true, false);
- }
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(false, true, false);
@Override
public String encrypt(final Object plainValue, final AlgorithmSQLContext
algorithmSQLContext) {
diff --git
a/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java
b/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java
index 58a8f4dfb69..e5b21606526 100644
---
a/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java
+++
b/test/e2e/fixture/src/test/java/org/apache/shardingsphere/test/e2e/fixture/ITEncryptLikeAlgorithmFixture.java
@@ -61,7 +61,7 @@ public final class ITEncryptLikeAlgorithmFixture implements
EncryptAlgorithm {
private Map<Character, Integer> charIndexes;
@Getter
- private EncryptAlgorithmMetaData metaData;
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(false, true, true);
@Override
public void init(final Properties props) {
@@ -69,7 +69,6 @@ public final class ITEncryptLikeAlgorithmFixture implements
EncryptAlgorithm {
mask = createMask(props);
start = createStart(props);
charIndexes = createCharIndexes(props);
- metaData = new EncryptAlgorithmMetaData(false, true, true);
}
private int createDelta(final Properties props) {
diff --git
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java
index 2ab978b1b0c..e3c1a88245c 100644
---
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java
+++
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryAssistedEncryptAlgorithmFixture.java
@@ -22,17 +22,10 @@ import
org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
-import java.util.Properties;
-
@Getter
public final class RewriteQueryAssistedEncryptAlgorithmFixture implements
EncryptAlgorithm {
- private EncryptAlgorithmMetaData metaData;
-
- @Override
- public void init(final Properties props) {
- metaData = new EncryptAlgorithmMetaData(false, true, false);
- }
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(false, true, false);
@Override
public String encrypt(final Object plainValue, final AlgorithmSQLContext
algorithmSQLContext) {
diff --git
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java
index 58a13207574..21913c0ac51 100644
---
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java
+++
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/fixture/encrypt/RewriteQueryLikeEncryptAlgorithmFixture.java
@@ -22,17 +22,10 @@ import
org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
-import java.util.Properties;
-
@Getter
public final class RewriteQueryLikeEncryptAlgorithmFixture implements
EncryptAlgorithm {
- private EncryptAlgorithmMetaData metaData;
-
- @Override
- public void init(final Properties props) {
- metaData = new EncryptAlgorithmMetaData(false, true, true);
- }
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(false, true, true);
@Override
public String encrypt(final Object plainValue, final AlgorithmSQLContext
algorithmSQLContext) {
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/algorithm/TestQueryAssistedShardingEncryptAlgorithm.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/algorithm/TestQueryAssistedShardingEncryptAlgorithm.java
index 4a2520b6b7c..3bbf6ee4846 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/algorithm/TestQueryAssistedShardingEncryptAlgorithm.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/commons/algorithm/TestQueryAssistedShardingEncryptAlgorithm.java
@@ -22,20 +22,10 @@ import
org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithmMetaData;
import
org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
-import java.util.Properties;
-
@Getter
public final class TestQueryAssistedShardingEncryptAlgorithm implements
EncryptAlgorithm {
- private Properties properties;
-
- private EncryptAlgorithmMetaData metaData;
-
- @Override
- public void init(final Properties props) {
- this.properties = props;
- metaData = new EncryptAlgorithmMetaData(false, true, false);
- }
+ private final EncryptAlgorithmMetaData metaData = new
EncryptAlgorithmMetaData(false, true, false);
@Override
public String encrypt(final Object plainValue, final AlgorithmSQLContext
algorithmSQLContext) {