cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] branch master updated: cayenne-crypto cleanup
Date Thu, 11 Apr 2019 12:53:03 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 314a1bf  cayenne-crypto cleanup
314a1bf is described below

commit 314a1bfc8950b8b5d5a8af7a64302eed52989400
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Thu Apr 11 15:51:40 2019 +0300

    cayenne-crypto cleanup
---
 .../transformer/value/Utf8StringConverter.java     |  8 ++------
 .../transformer/value/DefaultEncryptorTest.java    | 23 +++++++++-------------
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/Utf8StringConverter.java
b/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/Utf8StringConverter.java
index 23d6ae0..2748f53 100644
--- a/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/Utf8StringConverter.java
+++ b/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/Utf8StringConverter.java
@@ -25,15 +25,11 @@ import java.nio.charset.Charset;
  */
 public final class Utf8StringConverter implements BytesConverter<String> {
 
-    static final String DEFAULT_CHARSET = "UTF-8";
-
     public static final BytesConverter<String> INSTANCE = new Utf8StringConverter();
 
-    private Charset utf8;
+    static Charset utf8 = Charset.forName("UTF-8");
 
-    Utf8StringConverter() {
-        this.utf8 = Charset.forName(DEFAULT_CHARSET);
-    }
+    Utf8StringConverter() {}
 
     @Override
     public byte[] toBytes(String value) {
diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java
b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java
index 62c3845..21e250c 100644
--- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java
+++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java
@@ -18,27 +18,22 @@
  ****************************************************************/
 package org.apache.cayenne.crypto.transformer.value;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
 import java.io.UnsupportedEncodingException;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 import java.util.Base64;
 
-import javax.crypto.BadPaddingException;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-
 import org.apache.cayenne.crypto.transformer.bytes.BytesDecryptor;
 import org.apache.cayenne.crypto.transformer.bytes.BytesEncryptor;
 import org.apache.cayenne.crypto.unit.SwapBytesTransformer;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+
 public class DefaultEncryptorTest {
 
     private BytesEncryptor encryptor;
@@ -88,12 +83,12 @@ public class DefaultEncryptorTest {
         byte[] b1_t = (byte[]) e.encrypt(encryptor, s1);
 
         assertNotNull(b1_t);
-        assertEquals(s1, new String(decryptor.decrypt(b1_t, 0, null), Utf8StringConverter.DEFAULT_CHARSET));
+        assertEquals(s1, new String(decryptor.decrypt(b1_t, 0, null), Utf8StringConverter.utf8.name()));
 
         byte[] b2_t = (byte[]) e.encrypt(encryptor, s2);
 
         assertNotNull(b2_t);
-        assertEquals(s2, new String(decryptor.decrypt(b2_t, 0, null), Utf8StringConverter.DEFAULT_CHARSET));
+        assertEquals(s2, new String(decryptor.decrypt(b2_t, 0, null), Utf8StringConverter.utf8.name()));
     }
 
     @Test
@@ -117,7 +112,7 @@ public class DefaultEncryptorTest {
         assertNotEquals(s1_t, s1);
 
         byte[] b1_t = Base64.getDecoder().decode(s1_t);
-        assertEquals(s1, new String(decryptor.decrypt(b1_t, 0, null), Utf8StringConverter.DEFAULT_CHARSET));
+        assertEquals(s1, new String(decryptor.decrypt(b1_t, 0, null), Utf8StringConverter.utf8.name()));
 
         String s2_t = (String) e.encrypt(encryptor, s2);
 
@@ -125,6 +120,6 @@ public class DefaultEncryptorTest {
         assertNotEquals(s2_t, s2);
 
         byte[] b2_t = Base64.getDecoder().decode(s2_t);
-        assertEquals(s2, new String(decryptor.decrypt(b2_t, 0, null), Utf8StringConverter.DEFAULT_CHARSET));
+        assertEquals(s2, new String(decryptor.decrypt(b2_t, 0, null), Utf8StringConverter.utf8.name()));
     }
 }


Mime
View raw message