This is an automated email from the ASF dual-hosted git repository.

zhaojinchao 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 eb13900d3f9 Add EncryptAlgorithmInitializeException (#20337)
eb13900d3f9 is described below

commit eb13900d3f9f4a8f8a928d387bd5a8e91c05ca4d
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Aug 21 22:16:47 2022 +0800

    Add EncryptAlgorithmInitializeException (#20337)
    
    * Add EncryptAlgorithmInitializeException
    
    * Add EncryptAlgorithmInitializeException
    
    * Add EncryptAlgorithmInitializeException
    
    * Add EncryptAlgorithmInitializeException
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../encrypt/algorithm/RC4EncryptAlgorithm.java     |  6 ++--
 .../EncryptAlgorithmInitializationException.java   | 33 ++++++++++++++++++++++
 .../encrypt/algorithm/RC4EncryptAlgorithmTest.java |  4 +--
 5 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md 
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 10d9a53b077..358d73962bb 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -22,5 +22,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | HY000     | 15000       | Work ID assigned failed, which can not exceed 1024 
|
 | HY000     | 16000       | Can not find pipeline job \`%s\` |
 | HY000     | 16001       | Failed to get DDL for table \`%s\` |
+| HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
 | HY004     | 25000       | Shadow column \`%s\` of table \`%s\` does not 
support \`%s\` type |
 | 42000     | 30000       | Unknown exception: %s |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md 
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index a6dbbb70256..4c1dabe4cb2 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -22,5 +22,6 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | HY000     | 15000       | Work ID assigned failed, which can not exceed 1024 
|
 | HY000     | 16000       | Can not find pipeline job \`%s\` |
 | HY000     | 16001       | Failed to get DDL for table \`%s\` |
+| HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
 | HY004     | 25000       | Shadow column \`%s\` of table \`%s\` does not 
support \`%s\` type |
 | 42000     | 30000       | Unknown exception: %s |
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithm.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithm.java
index ba3a2193ce2..64431b07b19 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithm.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithm.java
@@ -19,9 +19,9 @@ package org.apache.shardingsphere.encrypt.algorithm;
 
 import lombok.Getter;
 import org.apache.commons.codec.binary.Base64;
+import 
org.apache.shardingsphere.encrypt.exception.EncryptAlgorithmInitializationException;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
@@ -52,9 +52,9 @@ public final class RC4EncryptAlgorithm implements 
EncryptAlgorithm<Object, Strin
         setKey(props.getProperty(RC4_KEY, 
"").getBytes(StandardCharsets.UTF_8));
     }
     
-    private void setKey(final byte[] key) throws ShardingSphereException {
+    private void setKey(final byte[] key) {
         if (!(key.length >= KEY_MIN_LENGTH && key.length < SBOX_LENGTH)) {
-            throw new ShardingSphereException("Key length has to be between " 
+ KEY_MIN_LENGTH + " and " + (SBOX_LENGTH - 1));
+            throw new EncryptAlgorithmInitializationException("RC4", "Key 
length has to be between " + KEY_MIN_LENGTH + " and " + (SBOX_LENGTH - 1));
         }
         this.key = key;
     }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/EncryptAlgorithmInitializationException.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/EncryptAlgorithmInitializationException.java
new file mode 100644
index 00000000000..ae474c47be3
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/exception/EncryptAlgorithmInitializationException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.encrypt.exception;
+
+import 
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import 
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Encrypt algorithm initialization exception.
+ */
+public final class EncryptAlgorithmInitializationException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = -2004166948563207100L;
+    
+    public EncryptAlgorithmInitializationException(final String encryptorType, 
final String reason) {
+        super(XOpenSQLState.GENERAL_ERROR, 24000, "Encrypt algorithm `%s` 
initialization failed, reason is: %s", encryptorType, reason);
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithmTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithmTest.java
index 6c610ff21d0..81b0f6be8ff 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithmTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithmTest.java
@@ -17,11 +17,11 @@
 
 package org.apache.shardingsphere.encrypt.algorithm;
 
+import 
org.apache.shardingsphere.encrypt.exception.EncryptAlgorithmInitializationException;
 import org.apache.shardingsphere.encrypt.factory.EncryptAlgorithmFactory;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.encrypt.spi.context.EncryptContext;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -57,7 +57,7 @@ public final class RC4EncryptAlgorithmTest {
         assertNull(encryptAlgorithm.encrypt(null, mock(EncryptContext.class)));
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = EncryptAlgorithmInitializationException.class)
     public void assertKeyIsToLong() {
         encryptAlgorithm.init(createInvalidProperties());
     }

Reply via email to