cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1584630 - in /cayenne/main/trunk/cayenne-crypto/src: main/java/org/apache/cayenne/crypto/ main/java/org/apache/cayenne/crypto/transformer/ main/java/org/apache/cayenne/crypto/transformer/value/ test/java/org/apache/cayenne/crypto/ test/jav...
Date Fri, 04 Apr 2014 12:04:11 GMT
Author: aadamchik
Date: Fri Apr  4 12:04:11 2014
New Revision: 1584630

URL: http://svn.apache.org/r1584630
Log:
CAY-1916 cayenne-crypto module that enables data encryption for certain model attributes

splitting valuetransformer implementations into encryptor and decryptor

Added:
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultDecryptor.java
      - copied, changed from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptor.java
      - copied, changed from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactory.java
      - copied, changed from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactory.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueDecryptor.java
      - copied, changed from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueEncryptor.java
      - copied, changed from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java
      - copied, changed from r1584629, cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerTest.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java
      - copied, changed from r1584629, cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactoryTest.java
Removed:
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactory.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactoryTest.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerTest.java
Modified:
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultBindingsTransformer.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultMapTransformer.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultTransformerFactory.java
    cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformerFactory.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/CryptoModuleBuilderTest.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactory.java
    cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactoryTest.java

Modified: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java?rev=1584630&r1=1584629&r2=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/CryptoModuleBuilder.java
Fri Apr  4 12:04:11 2014
@@ -36,7 +36,7 @@ import org.apache.cayenne.crypto.transfo
 import org.apache.cayenne.crypto.transformer.TransformerFactory;
 import org.apache.cayenne.crypto.transformer.bytes.BytesTransformerFactory;
 import org.apache.cayenne.crypto.transformer.bytes.DefaultBytesTransformerFactory;
-import org.apache.cayenne.crypto.transformer.value.JceValueTransformerFactory;
+import org.apache.cayenne.crypto.transformer.value.DefaultValueTransformerFactory;
 import org.apache.cayenne.crypto.transformer.value.ValueTransformerFactory;
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.MapBuilder;
@@ -87,7 +87,7 @@ public class CryptoModuleBuilder {
 
         this.columnMapperPattern = "^CRYPTO_";
         
-        this.valueTransformerFactoryType = JceValueTransformerFactory.class;
+        this.valueTransformerFactoryType = DefaultValueTransformerFactory.class;
     }
 
     public CryptoModuleBuilder cipherAlgorithm(String algorithm) {

Modified: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultBindingsTransformer.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultBindingsTransformer.java?rev=1584630&r1=1584629&r2=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultBindingsTransformer.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultBindingsTransformer.java
Fri Apr  4 12:04:11 2014
@@ -21,7 +21,7 @@ package org.apache.cayenne.crypto.transf
 import javax.crypto.Cipher;
 
 import org.apache.cayenne.access.translator.batch.BatchParameterBinding;
-import org.apache.cayenne.crypto.transformer.value.ValueTransformer;
+import org.apache.cayenne.crypto.transformer.value.ValueEncryptor;
 
 /**
  * @since 3.2
@@ -29,10 +29,10 @@ import org.apache.cayenne.crypto.transfo
 public class DefaultBindingsTransformer implements BindingsTransformer {
 
     private int[] positions;
-    private ValueTransformer[] transformers;
+    private ValueEncryptor[] transformers;
     private Cipher cipher;
 
-    public DefaultBindingsTransformer(int[] positions, ValueTransformer[] transformers, Cipher
cipher) {
+    public DefaultBindingsTransformer(int[] positions, ValueEncryptor[] transformers, Cipher
cipher) {
         this.positions = positions;
         this.transformers = transformers;
         this.cipher = cipher;
@@ -45,7 +45,7 @@ public class DefaultBindingsTransformer 
 
         for (int i = 0; i < len; i++) {
             BatchParameterBinding b = bindings[positions[i]];
-            Object transformed = transformers[i].transform(cipher, b.getValue());
+            Object transformed = transformers[i].encrypt(cipher, b.getValue());
             b.setValue(transformed);
         }
     }

Modified: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultMapTransformer.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultMapTransformer.java?rev=1584630&r1=1584629&r2=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultMapTransformer.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultMapTransformer.java
Fri Apr  4 12:04:11 2014
@@ -22,7 +22,7 @@ import java.util.Map;
 
 import javax.crypto.Cipher;
 
-import org.apache.cayenne.crypto.transformer.value.ValueTransformer;
+import org.apache.cayenne.crypto.transformer.value.ValueDecryptor;
 
 /**
  * @since 3.2
@@ -30,10 +30,10 @@ import org.apache.cayenne.crypto.transfo
 public class DefaultMapTransformer implements MapTransformer {
 
     private String[] mapKeys;
-    private ValueTransformer[] transformers;
+    private ValueDecryptor[] transformers;
     private Cipher cipher;
 
-    public DefaultMapTransformer(String[] mapKeys, ValueTransformer[] transformers, Cipher
cipher) {
+    public DefaultMapTransformer(String[] mapKeys, ValueDecryptor[] transformers, Cipher
cipher) {
         this.mapKeys = mapKeys;
         this.transformers = transformers;
         this.cipher = cipher;
@@ -48,7 +48,7 @@ public class DefaultMapTransformer imple
             Object value = map.get(mapKeys[i]);
 
             if (value != null) {
-                Object transformed = transformers[i].transform(cipher, value);
+                Object transformed = transformers[i].decrypt(cipher, value);
                 map.put(mapKeys[i], transformed);
             }
         }

Modified: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultTransformerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultTransformerFactory.java?rev=1584630&r1=1584629&r2=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultTransformerFactory.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/DefaultTransformerFactory.java
Fri Apr  4 12:04:11 2014
@@ -26,7 +26,8 @@ import org.apache.cayenne.access.jdbc.Co
 import org.apache.cayenne.access.translator.batch.BatchParameterBinding;
 import org.apache.cayenne.crypto.cipher.CipherFactory;
 import org.apache.cayenne.crypto.map.ColumnMapper;
-import org.apache.cayenne.crypto.transformer.value.ValueTransformer;
+import org.apache.cayenne.crypto.transformer.value.ValueDecryptor;
+import org.apache.cayenne.crypto.transformer.value.ValueEncryptor;
 import org.apache.cayenne.crypto.transformer.value.ValueTransformerFactory;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DbAttribute;
@@ -73,7 +74,7 @@ public class DefaultTransformerFactory i
 
             int dlen = cryptoColumns.size();
             String[] mapKeys = new String[dlen];
-            ValueTransformer[] transformers = new ValueTransformer[dlen];
+            ValueDecryptor[] transformers = new ValueDecryptor[dlen];
 
             for (int i = 0; i < dlen; i++) {
 
@@ -110,7 +111,7 @@ public class DefaultTransformerFactory i
 
             int dlen = cryptoColumns.size();
             int[] positions = new int[dlen];
-            ValueTransformer[] transformers = new ValueTransformer[dlen];
+            ValueEncryptor[] transformers = new ValueEncryptor[dlen];
 
             for (int i = 0; i < dlen; i++) {
                 int pos = cryptoColumns.get(i);

Copied: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultDecryptor.java
(from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultDecryptor.java?p2=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultDecryptor.java&p1=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java&r1=1584629&r2=1584630&rev=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultDecryptor.java
Fri Apr  4 12:04:11 2014
@@ -27,12 +27,12 @@ import org.apache.cayenne.crypto.Cayenne
 /**
  * @since 3.2
  */
-public class JceValueTransformer implements ValueTransformer {
+class DefaultDecryptor implements ValueDecryptor {
 
     private BytesConverter preConverter;
     private BytesConverter postConverter;
 
-    public JceValueTransformer(BytesConverter preConverter, BytesConverter postConverter)
{
+    public DefaultDecryptor(BytesConverter preConverter, BytesConverter postConverter) {
         this.preConverter = preConverter;
         this.postConverter = postConverter;
     }
@@ -46,7 +46,7 @@ public class JceValueTransformer impleme
     }
 
     @Override
-    public Object transform(Cipher cipher, Object value) {
+    public Object decrypt(Cipher cipher, Object value) {
 
         byte[] bytes = preConverter.toBytes(value);
         byte[] transformed;

Copied: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptor.java
(from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptor.java?p2=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptor.java&p1=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java&r1=1584629&r2=1584630&rev=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformer.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptor.java
Fri Apr  4 12:04:11 2014
@@ -27,12 +27,12 @@ import org.apache.cayenne.crypto.Cayenne
 /**
  * @since 3.2
  */
-public class JceValueTransformer implements ValueTransformer {
+class DefaultEncryptor implements ValueEncryptor {
 
     private BytesConverter preConverter;
     private BytesConverter postConverter;
 
-    public JceValueTransformer(BytesConverter preConverter, BytesConverter postConverter)
{
+    public DefaultEncryptor(BytesConverter preConverter, BytesConverter postConverter) {
         this.preConverter = preConverter;
         this.postConverter = postConverter;
     }
@@ -46,7 +46,7 @@ public class JceValueTransformer impleme
     }
 
     @Override
-    public Object transform(Cipher cipher, Object value) {
+    public Object encrypt(Cipher cipher, Object value) {
 
         byte[] bytes = preConverter.toBytes(value);
         byte[] transformed;

Copied: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactory.java
(from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactory.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactory.java?p2=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactory.java&p1=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactory.java&r1=1584629&r2=1584630&rev=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactory.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactory.java
Fri Apr  4 12:04:11 2014
@@ -39,7 +39,7 @@ import org.apache.cayenne.map.ObjEntity;
  * 
  * @since 3.2
  */
-public class JceValueTransformerFactory implements ValueTransformerFactory {
+public class DefaultValueTransformerFactory implements ValueTransformerFactory {
 
     private Map<String, BytesConverter> objectToBytes;
     private Map<Integer, BytesConverter> dbToBytes;
@@ -47,12 +47,12 @@ public class JceValueTransformerFactory 
     private Map<String, BytesConverter> bytesToObject;
     private Map<Integer, BytesConverter> bytesToDb;
 
-    private ConcurrentMap<DbAttribute, ValueTransformer> encryptors;
-    private ConcurrentMap<DbAttribute, ValueTransformer> decryptors;
+    private ConcurrentMap<DbAttribute, ValueEncryptor> encryptors;
+    private ConcurrentMap<DbAttribute, ValueDecryptor> decryptors;
 
-    public JceValueTransformerFactory() {
-        this.encryptors = new ConcurrentHashMap<DbAttribute, ValueTransformer>();
-        this.decryptors = new ConcurrentHashMap<DbAttribute, ValueTransformer>();
+    public DefaultValueTransformerFactory() {
+        this.encryptors = new ConcurrentHashMap<DbAttribute, ValueEncryptor>();
+        this.decryptors = new ConcurrentHashMap<DbAttribute, ValueDecryptor>();
 
         this.objectToBytes = createObjectToBytesConverters();
         this.dbToBytes = createDbToBytesConverters();
@@ -61,13 +61,13 @@ public class JceValueTransformerFactory 
     }
 
     @Override
-    public ValueTransformer decryptor(DbAttribute a) {
-        ValueTransformer e = decryptors.get(a);
+    public ValueDecryptor decryptor(DbAttribute a) {
+        ValueDecryptor e = decryptors.get(a);
 
         if (e == null) {
 
-            ValueTransformer newTransformer = createDecryptor(a);
-            ValueTransformer oldTransformer = decryptors.putIfAbsent(a, newTransformer);
+            ValueDecryptor newTransformer = createDecryptor(a);
+            ValueDecryptor oldTransformer = decryptors.putIfAbsent(a, newTransformer);
 
             e = oldTransformer != null ? oldTransformer : newTransformer;
         }
@@ -76,13 +76,13 @@ public class JceValueTransformerFactory 
     }
 
     @Override
-    public ValueTransformer encryptor(DbAttribute a) {
-        ValueTransformer e = encryptors.get(a);
+    public ValueEncryptor encryptor(DbAttribute a) {
+        ValueEncryptor e = encryptors.get(a);
 
         if (e == null) {
 
-            ValueTransformer newTransformer = createEncryptor(a);
-            ValueTransformer oldTransformer = encryptors.putIfAbsent(a, newTransformer);
+            ValueEncryptor newTransformer = createEncryptor(a);
+            ValueEncryptor oldTransformer = encryptors.putIfAbsent(a, newTransformer);
 
             e = oldTransformer != null ? oldTransformer : newTransformer;
         }
@@ -141,7 +141,7 @@ public class JceValueTransformerFactory 
         return map;
     }
 
-    protected ValueTransformer createEncryptor(DbAttribute a) {
+    protected ValueEncryptor createEncryptor(DbAttribute a) {
 
         String type = getJavaType(a);
 
@@ -157,10 +157,10 @@ public class JceValueTransformerFactory 
                     + " for attribute " + a + " has no bytes-to-db conversion");
         }
 
-        return new JceValueTransformer(toBytes, fromBytes);
+        return new DefaultEncryptor(toBytes, fromBytes);
     }
 
-    protected ValueTransformer createDecryptor(DbAttribute a) {
+    protected ValueDecryptor createDecryptor(DbAttribute a) {
 
         BytesConverter toBytes = dbToBytes.get(a.getType());
         if (toBytes == null) {
@@ -175,7 +175,7 @@ public class JceValueTransformerFactory 
                     + " has no bytes-to-object conversion");
         }
 
-        return new JceValueTransformer(toBytes, fromBytes);
+        return new DefaultDecryptor(toBytes, fromBytes);
     }
 
     // TODO: calculating Java type of ObjAttribute may become unneeded per

Copied: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueDecryptor.java
(from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueDecryptor.java?p2=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueDecryptor.java&p1=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java&r1=1584629&r2=1584630&rev=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueDecryptor.java
Fri Apr  4 12:04:11 2014
@@ -21,16 +21,13 @@ package org.apache.cayenne.crypto.transf
 import javax.crypto.Cipher;
 
 /**
- * An encryptor or decryptor of a single value.
- * 
  * @since 3.2
  */
-public interface ValueTransformer {
-
+public interface ValueDecryptor {
     /**
      * Transforms a value using the provided Cipher. Cipher is assumed to be
      * fully initialized for the right operation (encryption or decryption) and
      * its state reset from any previous operations.
      */
-    Object transform(Cipher cipher, Object value);
+    Object decrypt(Cipher cipher, Object value);
 }

Copied: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueEncryptor.java
(from r1584629, cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueEncryptor.java?p2=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueEncryptor.java&p1=cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java&r1=1584629&r2=1584630&rev=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformer.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueEncryptor.java
Fri Apr  4 12:04:11 2014
@@ -25,12 +25,12 @@ import javax.crypto.Cipher;
  * 
  * @since 3.2
  */
-public interface ValueTransformer {
+public interface ValueEncryptor {
 
     /**
      * Transforms a value using the provided Cipher. Cipher is assumed to be
      * fully initialized for the right operation (encryption or decryption) and
      * its state reset from any previous operations.
      */
-    Object transform(Cipher cipher, Object value);
+    Object encrypt(Cipher cipher, Object value);
 }

Modified: cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformerFactory.java?rev=1584630&r1=1584629&r2=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformerFactory.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/main/java/org/apache/cayenne/crypto/transformer/value/ValueTransformerFactory.java
Fri Apr  4 12:04:11 2014
@@ -28,7 +28,7 @@ import org.apache.cayenne.map.DbAttribut
  */
 public interface ValueTransformerFactory {
 
-    ValueTransformer encryptor(DbAttribute a);
+    ValueEncryptor encryptor(DbAttribute a);
 
-    ValueTransformer decryptor(DbAttribute a);
+    ValueDecryptor decryptor(DbAttribute a);
 }

Modified: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/CryptoModuleBuilderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/CryptoModuleBuilderTest.java?rev=1584630&r1=1584629&r2=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/CryptoModuleBuilderTest.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/CryptoModuleBuilderTest.java
Fri Apr  4 12:04:11 2014
@@ -25,7 +25,7 @@ import java.security.Key;
 
 import org.apache.cayenne.crypto.key.KeySource;
 import org.apache.cayenne.crypto.key.JceksKeySourceTest;
-import org.apache.cayenne.crypto.transformer.value.JceValueTransformerFactory;
+import org.apache.cayenne.crypto.transformer.value.DefaultValueTransformerFactory;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.Module;
@@ -37,7 +37,7 @@ public class CryptoModuleBuilderTest {
     public void testBuild_KeySource() {
         Module m = new CryptoModuleBuilder().keyPassword(JceksKeySourceTest.TEST_KEY_PASS)
                 .keyStore(JceksKeySourceTest.class.getResource(JceksKeySourceTest.KS1_JCEKS))
-                .valueTransformer(JceValueTransformerFactory.class).build();
+                .valueTransformer(DefaultValueTransformerFactory.class).build();
 
         Injector injector = DIBootstrap.createInjector(m);
 

Copied: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java
(from r1584629, cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerTest.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java?p2=cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java&p1=cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerTest.java&r1=1584629&r2=1584630&rev=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerTest.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultEncryptorTest.java
Fri Apr  4 12:04:11 2014
@@ -38,7 +38,7 @@ import javax.xml.bind.DatatypeConverter;
 import org.junit.Before;
 import org.junit.Test;
 
-public class JceValueTransformerTest {
+public class DefaultEncryptorTest {
 
     private Cipher encCipher;
     private Cipher decCipher;
@@ -62,18 +62,18 @@ public class JceValueTransformerTest {
     @Test
     public void testTransform_BytesToBytes() throws IllegalBlockSizeException, BadPaddingException
{
 
-        JceValueTransformer e = new JceValueTransformer(BytesToBytesConverter.INSTANCE, BytesToBytesConverter.INSTANCE);
+        DefaultEncryptor e = new DefaultEncryptor(BytesToBytesConverter.INSTANCE, BytesToBytesConverter.INSTANCE);
 
         byte[] b1 = new byte[] { 1, 2 };
         byte[] b2 = new byte[] { 2, 3 };
 
-        byte[] b1_t = (byte[]) e.transform(encCipher, b1);
+        byte[] b1_t = (byte[]) e.encrypt(encCipher, b1);
 
         assertNotNull(b1_t);
         assertEquals(encCipher.getBlockSize(), b1_t.length);
         assertArrayEquals(b1, decCipher.doFinal(b1_t));
 
-        byte[] b2_t = (byte[]) e.transform(encCipher, b2);
+        byte[] b2_t = (byte[]) e.encrypt(encCipher, b2);
 
         assertNotNull(b2_t);
         assertEquals(encCipher.getBlockSize(), b2_t.length);
@@ -83,7 +83,7 @@ public class JceValueTransformerTest {
     @Test
     public void testTransform_BytesToBytes_DifferentSizes() {
 
-        JceValueTransformer e = new JceValueTransformer(BytesToBytesConverter.INSTANCE, BytesToBytesConverter.INSTANCE);
+        DefaultEncryptor e = new DefaultEncryptor(BytesToBytesConverter.INSTANCE, BytesToBytesConverter.INSTANCE);
 
         int blockSize = encCipher.getBlockSize();
 
@@ -101,19 +101,19 @@ public class JceValueTransformerTest {
             b5[i] = (byte) i;
         }
 
-        byte[] b1_t = (byte[]) e.transform(encCipher, b1);
+        byte[] b1_t = (byte[]) e.encrypt(encCipher, b1);
         assertEquals(encCipher.getBlockSize(), b1_t.length);
 
-        byte[] b2_t = (byte[]) e.transform(encCipher, b2);
+        byte[] b2_t = (byte[]) e.encrypt(encCipher, b2);
         assertEquals(encCipher.getBlockSize(), b2_t.length);
 
-        byte[] b3_t = (byte[]) e.transform(encCipher, b3);
+        byte[] b3_t = (byte[]) e.encrypt(encCipher, b3);
         assertEquals(encCipher.getBlockSize(), b3_t.length);
 
-        byte[] b4_t = (byte[]) e.transform(encCipher, b4);
+        byte[] b4_t = (byte[]) e.encrypt(encCipher, b4);
         assertEquals(encCipher.getBlockSize() * 2, b4_t.length);
 
-        byte[] b5_t = (byte[]) e.transform(encCipher, b5);
+        byte[] b5_t = (byte[]) e.encrypt(encCipher, b5);
         assertEquals(encCipher.getBlockSize() * 2, b5_t.length);
     }
 
@@ -121,18 +121,18 @@ public class JceValueTransformerTest {
     public void testTransform_StringToBytes() throws UnsupportedEncodingException, IllegalBlockSizeException,
             BadPaddingException {
 
-        JceValueTransformer e = new JceValueTransformer(Utf8StringConverter.INSTANCE, BytesToBytesConverter.INSTANCE);
+        DefaultEncryptor e = new DefaultEncryptor(Utf8StringConverter.INSTANCE, BytesToBytesConverter.INSTANCE);
 
         String s1 = "ab";
         String s2 = "cd";
 
-        byte[] b1_t = (byte[]) e.transform(encCipher, s1);
+        byte[] b1_t = (byte[]) e.encrypt(encCipher, s1);
 
         assertNotNull(b1_t);
         assertEquals(encCipher.getBlockSize(), b1_t.length);
         assertEquals(s1, new String(decCipher.doFinal(b1_t), Utf8StringConverter.DEFAULT_CHARSET));
 
-        byte[] b2_t = (byte[]) e.transform(encCipher, s2);
+        byte[] b2_t = (byte[]) e.encrypt(encCipher, s2);
 
         assertNotNull(b2_t);
         assertEquals(encCipher.getBlockSize(), b2_t.length);
@@ -143,7 +143,7 @@ public class JceValueTransformerTest {
     public void testTransform_StringToString() throws UnsupportedEncodingException, IllegalBlockSizeException,
             BadPaddingException {
 
-        JceValueTransformer e = new JceValueTransformer(Utf8StringConverter.INSTANCE, Base64StringConverter.INSTANCE);
+        DefaultEncryptor e = new DefaultEncryptor(Utf8StringConverter.INSTANCE, Base64StringConverter.INSTANCE);
 
         String s1 = "ab";
 
@@ -154,7 +154,7 @@ public class JceValueTransformerTest {
                 + "Donec convallis mi vitae luctus rutrum. Sed ut imperdiet ante. Praesent
condimentum velit eget "
                 + "felis pretium blandit. Praesent lacus tortor, facilisis eget sapien quis,
hendrerit iaculis tellus.";
 
-        String s1_t = (String) e.transform(encCipher, s1);
+        String s1_t = (String) e.encrypt(encCipher, s1);
 
         assertNotNull(s1_t);
         assertNotEquals(s1_t, s1);
@@ -162,7 +162,7 @@ public class JceValueTransformerTest {
         byte[] b1_t = DatatypeConverter.parseBase64Binary(s1_t);
         assertEquals(s1, new String(decCipher.doFinal(b1_t), Utf8StringConverter.DEFAULT_CHARSET));
 
-        String s2_t = (String) e.transform(encCipher, s2);
+        String s2_t = (String) e.encrypt(encCipher, s2);
 
         assertNotNull(s2_t);
         assertNotEquals(s2_t, s2);

Copied: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java
(from r1584629, cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactoryTest.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java?p2=cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java&p1=cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactoryTest.java&r1=1584629&r2=1584630&rev=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/JceValueTransformerFactoryTest.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/transformer/value/DefaultValueTransformerFactoryTest.java
Fri Apr  4 12:04:11 2014
@@ -33,7 +33,7 @@ import org.apache.cayenne.map.DbEntity;
 import org.junit.Before;
 import org.junit.Test;
 
-public class JceValueTransformerFactoryTest {
+public class DefaultValueTransformerFactoryTest {
 
     private DbEntity t1;
     private DbEntity t2;
@@ -50,7 +50,7 @@ public class JceValueTransformerFactoryT
     @Test
     public void testGetJavaType() {
 
-        JceValueTransformerFactory f = new JceValueTransformerFactory();
+        DefaultValueTransformerFactory f = new DefaultValueTransformerFactory();
 
         DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING");
         assertEquals("java.lang.String", f.getJavaType(t1_ct));
@@ -78,68 +78,68 @@ public class JceValueTransformerFactoryT
 
     @Test
     public void testCreateEncryptor() {
-        JceValueTransformerFactory f = new JceValueTransformerFactory();
+        DefaultValueTransformerFactory f = new DefaultValueTransformerFactory();
 
         DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING");
 
-        ValueTransformer t1 = f.createEncryptor(t1_ct);
+        ValueEncryptor t1 = f.createEncryptor(t1_ct);
         assertNotNull(t1);
-        assertTrue(t1 instanceof JceValueTransformer);
-        assertSame(Utf8StringConverter.INSTANCE, ((JceValueTransformer) t1).getPreConverter());
-        assertSame(Base64StringConverter.INSTANCE, ((JceValueTransformer) t1).getPostConverter());
+        assertTrue(t1 instanceof DefaultEncryptor);
+        assertSame(Utf8StringConverter.INSTANCE, ((DefaultEncryptor) t1).getPreConverter());
+        assertSame(Base64StringConverter.INSTANCE, ((DefaultEncryptor) t1).getPostConverter());
 
         DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES");
 
-        ValueTransformer t2 = f.createEncryptor(t2_cb);
+        ValueEncryptor t2 = f.createEncryptor(t2_cb);
         assertNotNull(t2);
-        assertTrue(t2 instanceof JceValueTransformer);
-        assertSame(BytesToBytesConverter.INSTANCE, ((JceValueTransformer) t2).getPreConverter());
-        assertSame(BytesToBytesConverter.INSTANCE, ((JceValueTransformer) t2).getPostConverter());
+        assertTrue(t2 instanceof DefaultEncryptor);
+        assertSame(BytesToBytesConverter.INSTANCE, ((DefaultEncryptor) t2).getPreConverter());
+        assertSame(BytesToBytesConverter.INSTANCE, ((DefaultEncryptor) t2).getPostConverter());
     }
 
     @Test
     public void testCreateDecryptor() {
-        JceValueTransformerFactory f = new JceValueTransformerFactory();
+        DefaultValueTransformerFactory f = new DefaultValueTransformerFactory();
 
         DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING");
 
-        ValueTransformer t1 = f.createDecryptor(t1_ct);
+        ValueDecryptor t1 = f.createDecryptor(t1_ct);
         assertNotNull(t1);
-        assertTrue(t1 instanceof JceValueTransformer);
-        assertSame(Base64StringConverter.INSTANCE, ((JceValueTransformer) t1).getPreConverter());
-        assertSame(Utf8StringConverter.INSTANCE, ((JceValueTransformer) t1).getPostConverter());
+        assertTrue(t1 instanceof DefaultDecryptor);
+        assertSame(Base64StringConverter.INSTANCE, ((DefaultDecryptor) t1).getPreConverter());
+        assertSame(Utf8StringConverter.INSTANCE, ((DefaultDecryptor) t1).getPostConverter());
 
         DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES");
 
-        ValueTransformer t2 = f.createDecryptor(t2_cb);
+        ValueDecryptor t2 = f.createDecryptor(t2_cb);
         assertNotNull(t2);
-        assertTrue(t2 instanceof JceValueTransformer);
-        assertSame(BytesToBytesConverter.INSTANCE, ((JceValueTransformer) t2).getPreConverter());
-        assertSame(BytesToBytesConverter.INSTANCE, ((JceValueTransformer) t2).getPostConverter());
+        assertTrue(t2 instanceof DefaultDecryptor);
+        assertSame(BytesToBytesConverter.INSTANCE, ((DefaultDecryptor) t2).getPreConverter());
+        assertSame(BytesToBytesConverter.INSTANCE, ((DefaultDecryptor) t2).getPostConverter());
 
         DbAttribute t3_cb = t3.getAttribute("CRYPTO_BYTES");
 
-        ValueTransformer t3 = f.createDecryptor(t3_cb);
+        ValueDecryptor t3 = f.createDecryptor(t3_cb);
         assertNotNull(t3);
-        assertTrue(t3 instanceof JceValueTransformer);
-        assertSame(BytesToBytesConverter.INSTANCE, ((JceValueTransformer) t3).getPreConverter());
-        assertSame(Utf8StringConverter.INSTANCE, ((JceValueTransformer) t3).getPostConverter());
+        assertTrue(t3 instanceof DefaultDecryptor);
+        assertSame(BytesToBytesConverter.INSTANCE, ((DefaultDecryptor) t3).getPreConverter());
+        assertSame(Utf8StringConverter.INSTANCE, ((DefaultDecryptor) t3).getPostConverter());
     }
 
     @Test
     public void testEncryptor() {
-        JceValueTransformerFactory f = new JceValueTransformerFactory();
+        DefaultValueTransformerFactory f = new DefaultValueTransformerFactory();
 
         DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING");
 
-        ValueTransformer t1 = f.encryptor(t1_ct);
+        ValueEncryptor t1 = f.encryptor(t1_ct);
         assertNotNull(t1);
         assertSame(t1, f.encryptor(t1_ct));
         assertSame(t1, f.encryptor(t1_ct));
 
         DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES");
 
-        ValueTransformer t2 = f.encryptor(t2_cb);
+        ValueEncryptor t2 = f.encryptor(t2_cb);
         assertNotNull(t2);
         assertSame(t2, f.encryptor(t2_cb));
         assertSame(t2, f.encryptor(t2_cb));
@@ -147,18 +147,18 @@ public class JceValueTransformerFactoryT
     
     @Test
     public void testDecryptor() {
-        JceValueTransformerFactory f = new JceValueTransformerFactory();
+        DefaultValueTransformerFactory f = new DefaultValueTransformerFactory();
 
         DbAttribute t1_ct = t1.getAttribute("CRYPTO_STRING");
 
-        ValueTransformer t1 = f.decryptor(t1_ct);
+        ValueDecryptor t1 = f.decryptor(t1_ct);
         assertNotNull(t1);
         assertSame(t1, f.decryptor(t1_ct));
         assertSame(t1, f.decryptor(t1_ct));
 
         DbAttribute t2_cb = t2.getAttribute("CRYPTO_BYTES");
 
-        ValueTransformer t2 = f.decryptor(t2_cb);
+        ValueDecryptor t2 = f.decryptor(t2_cb);
         assertNotNull(t2);
         assertSame(t2, f.decryptor(t2_cb));
         assertSame(t2, f.decryptor(t2_cb));

Modified: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactory.java?rev=1584630&r1=1584629&r2=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactory.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactory.java
Fri Apr  4 12:04:11 2014
@@ -22,13 +22,15 @@ import java.io.UnsupportedEncodingExcept
 
 import javax.crypto.Cipher;
 
-import org.apache.cayenne.crypto.transformer.value.ValueTransformer;
+import org.apache.cayenne.crypto.transformer.value.ValueDecryptor;
+import org.apache.cayenne.crypto.transformer.value.ValueEncryptor;
 import org.apache.cayenne.crypto.transformer.value.ValueTransformerFactory;
 import org.apache.cayenne.map.DbAttribute;
 
 public class Rot13TransformerFactory implements ValueTransformerFactory {
 
-    private ValueTransformer stringTransformer;
+    private ValueEncryptor stringEncryptor;
+    private ValueDecryptor stringDecryptor;
 
     public static String rotate(String value) {
         if (value == null) {
@@ -65,10 +67,18 @@ public class Rot13TransformerFactory imp
     }
 
     public Rot13TransformerFactory() {
-        this.stringTransformer = new ValueTransformer() {
+        this.stringEncryptor = new ValueEncryptor() {
 
             @Override
-            public Object transform(Cipher cipher, Object value) {
+            public Object encrypt(Cipher cipher, Object value) {
+                return value != null ? rotate(value.toString()) : null;
+            }
+        };
+        
+        this.stringDecryptor = new ValueDecryptor() {
+
+            @Override
+            public Object decrypt(Cipher cipher, Object value) {
                 return value != null ? rotate(value.toString()) : null;
             }
         };
@@ -76,12 +86,12 @@ public class Rot13TransformerFactory imp
     }
 
     @Override
-    public ValueTransformer decryptor(DbAttribute a) {
-        return stringTransformer;
+    public ValueDecryptor decryptor(DbAttribute a) {
+        return stringDecryptor;
     }
 
     @Override
-    public ValueTransformer encryptor(DbAttribute a) {
-        return stringTransformer;
+    public ValueEncryptor encryptor(DbAttribute a) {
+        return stringEncryptor;
     }
 }

Modified: cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactoryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactoryTest.java?rev=1584630&r1=1584629&r2=1584630&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactoryTest.java
(original)
+++ cayenne/main/trunk/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/unit/Rot13TransformerFactoryTest.java
Fri Apr  4 12:04:11 2014
@@ -29,14 +29,14 @@ public class Rot13TransformerFactoryTest
     public void testEncrypt() {
 
         Rot13TransformerFactory factory = new Rot13TransformerFactory();
-        assertEquals("nop", factory.encryptor(new DbAttribute()).transform(null, "abc"));
+        assertEquals("nop", factory.encryptor(new DbAttribute()).encrypt(null, "abc"));
     }
 
     @Test
     public void testDecrypt() {
 
         Rot13TransformerFactory factory = new Rot13TransformerFactory();
-        assertEquals("nop", factory.decryptor(new DbAttribute()).transform(null, "abc"));
+        assertEquals("nop", factory.decryptor(new DbAttribute()).decrypt(null, "abc"));
     }
 
 }



Mime
View raw message