zhujt20 commented on code in PR #233:
URL: https://github.com/apache/tsfile/pull/233#discussion_r1810449782


##########
java/tsfile/src/main/java/org/apache/tsfile/encrypt/IDecryptor.java:
##########
@@ -20,47 +20,30 @@
 package org.apache.tsfile.encrypt;
 
 import org.apache.tsfile.exception.encrypt.EncryptException;
-import org.apache.tsfile.exception.encrypt.EncryptKeyLengthNotMatchException;
 import org.apache.tsfile.file.metadata.enums.EncryptionType;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
+import java.lang.reflect.InvocationTargetException;
 
 /** encrypt data according to tsfileconfig. */
 public interface IDecryptor {
 
   static final Logger logger = LoggerFactory.getLogger(IDecryptor.class);
 
-  static IDecryptor getDecryptor(String name, byte[] key) {
-    return getDecryptor(EncryptionType.valueOf(name), key);
-  }
-
-  static IDecryptor getDecryptor(EncryptionType name, byte[] key) {
-    if (name == null) {
-      return new NoDecryptor();
-    }
-    switch (name) {
-      case UNENCRYPTED:
-        return new NoDecryptor();
-      case SM4128:
-        return new SM4128Decryptor(key);
-      case AES128:
-        return new AES128Decryptor(key);
-      default:
-        logger.warn("Unknown encryption type: {}", name);
-        return new NoDecryptor();
+  static IDecryptor getDecryptor(String type, byte[] key) {
+    try {
+      Class<?> encryptClass = Class.forName(type);
+      java.lang.reflect.Constructor<?> constructor =
+          encryptClass.getDeclaredConstructor(byte[].class);
+      return ((IEncrypt) constructor.newInstance(key)).getDecryptor();

Review Comment:
    storing the constructor we often use is good, but I don't understand why 
using a concurrent map to store the constructor and where to implement it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to