From afa3d61ed12af8f727104b23b66a8510d5545342 Mon Sep 17 00:00:00 2001 From: dianfu Date: Wed, 11 Nov 2015 17:44:19 +0800 Subject: [PATCH] Rename ChimeraUtils to Utils --- src/main/java/com/intel/chimera/CryptoCodec.java | 5 +++-- .../java/com/intel/chimera/CryptoInputStream.java | 11 ++++++----- .../java/com/intel/chimera/CryptoOutputStream.java | 11 ++++++----- .../java/com/intel/chimera/JceAesCtrCryptoCodec.java | 5 +++-- .../com/intel/chimera/OpensslAesCtrCryptoCodec.java | 3 ++- src/main/java/com/intel/chimera/VERSION | 1 - .../java/com/intel/chimera/random/OsSecureRandom.java | 4 ++-- .../com/intel/chimera/utils/NativeCodeLoader.java | 7 +++---- .../chimera/{ChimeraUtils.java => utils/Utils.java} | 8 +++++--- 9 files changed, 30 insertions(+), 25 deletions(-) delete mode 100644 src/main/java/com/intel/chimera/VERSION rename src/main/java/com/intel/chimera/{ChimeraUtils.java => utils/Utils.java} (97%) diff --git a/src/main/java/com/intel/chimera/CryptoCodec.java b/src/main/java/com/intel/chimera/CryptoCodec.java index 057ee3012..cf20bdf7e 100644 --- a/src/main/java/com/intel/chimera/CryptoCodec.java +++ b/src/main/java/com/intel/chimera/CryptoCodec.java @@ -26,6 +26,7 @@ import com.google.common.base.Splitter; import com.google.common.collect.Lists; +import com.intel.chimera.utils.Utils; import com.intel.chimera.utils.ReflectionUtils; /** @@ -99,13 +100,13 @@ public static CryptoCodec getInstance() { * crypto codec classes with cipher suite configured. */ public static CryptoCodec getInstance(Properties props) { - return getInstance(props, ChimeraUtils.getCryptoSuite(props)); + return getInstance(props, Utils.getCryptoSuite(props)); } private static List> getCodecClasses( Properties props, CipherSuite cipherSuite) { List> result = Lists.newArrayList(); - String codecString = ChimeraUtils.getCodecString(props, cipherSuite); + String codecString = Utils.getCodecString(props, cipherSuite); if (codecString == null) { LOG.debug( "No crypto codec classes with cipher suite configured."); diff --git a/src/main/java/com/intel/chimera/CryptoInputStream.java b/src/main/java/com/intel/chimera/CryptoInputStream.java index 27d98b263..51621a488 100644 --- a/src/main/java/com/intel/chimera/CryptoInputStream.java +++ b/src/main/java/com/intel/chimera/CryptoInputStream.java @@ -26,6 +26,7 @@ import java.util.Properties; import com.google.common.base.Preconditions; +import com.intel.chimera.utils.Utils; /** * CryptoInputStream decrypts data. It is not thread-safe. AES CTR mode is @@ -72,7 +73,7 @@ public class CryptoInputStream extends FilterInputStream implements public CryptoInputStream(Properties props, InputStream in, byte[] key, byte[] iv) throws IOException { - this(in, CryptoCodec.getInstance(props), ChimeraUtils.getBufferSize(props), key, iv); + this(in, CryptoCodec.getInstance(props), Utils.getBufferSize(props), key, iv); } public CryptoInputStream(InputStream in, CryptoCodec codec, @@ -88,8 +89,8 @@ public CryptoInputStream( byte[] iv, long streamOffset) throws IOException { super(in); - ChimeraUtils.checkCodec(codec); - this.bufferSize = ChimeraUtils.checkBufferSize(codec, bufferSize); + Utils.checkCodec(codec); + this.bufferSize = Utils.checkBufferSize(codec, bufferSize); this.input = getInput(in, bufferSize); this.codec = codec; this.key = key.clone(); @@ -375,8 +376,8 @@ private void checkStream() throws IOException { /** Forcibly free the direct buffers. */ private void freeBuffers() { - ChimeraUtils.freeDB(inBuffer); - ChimeraUtils.freeDB(outBuffer); + Utils.freeDB(inBuffer); + Utils.freeDB(outBuffer); } /** Get decryptor from pool */ diff --git a/src/main/java/com/intel/chimera/CryptoOutputStream.java b/src/main/java/com/intel/chimera/CryptoOutputStream.java index 0b4eb6311..940e97502 100644 --- a/src/main/java/com/intel/chimera/CryptoOutputStream.java +++ b/src/main/java/com/intel/chimera/CryptoOutputStream.java @@ -25,6 +25,7 @@ import java.util.Properties; import com.google.common.base.Preconditions; +import com.intel.chimera.utils.Utils; /** * CryptoOutputStream encrypts data. It is not thread-safe. AES CTR mode is @@ -69,7 +70,7 @@ public class CryptoOutputStream extends FilterOutputStream { public CryptoOutputStream(Properties props, OutputStream out, byte[] key, byte[] iv) throws IOException { - this(out, CryptoCodec.getInstance(props), ChimeraUtils.getBufferSize(props), key, iv); + this(out, CryptoCodec.getInstance(props), Utils.getBufferSize(props), key, iv); } public CryptoOutputStream(OutputStream out, CryptoCodec codec, @@ -81,8 +82,8 @@ public CryptoOutputStream(OutputStream out, CryptoCodec codec, int bufferSize, byte[] key, byte[] iv, long streamOffset) throws IOException { super(out); - ChimeraUtils.checkCodec(codec); - this.bufferSize = ChimeraUtils.checkBufferSize(codec, bufferSize); + Utils.checkCodec(codec); + this.bufferSize = Utils.checkBufferSize(codec, bufferSize); this.codec = codec; this.key = key.clone(); this.initIV = iv.clone(); @@ -238,7 +239,7 @@ private void checkStream() throws IOException { /** Forcibly free the direct buffers. */ private void freeBuffers() { - ChimeraUtils.freeDB(inBuffer); - ChimeraUtils.freeDB(outBuffer); + Utils.freeDB(inBuffer); + Utils.freeDB(outBuffer); } } diff --git a/src/main/java/com/intel/chimera/JceAesCtrCryptoCodec.java b/src/main/java/com/intel/chimera/JceAesCtrCryptoCodec.java index 6f809c957..3435f951d 100644 --- a/src/main/java/com/intel/chimera/JceAesCtrCryptoCodec.java +++ b/src/main/java/com/intel/chimera/JceAesCtrCryptoCodec.java @@ -31,6 +31,7 @@ import org.apache.commons.logging.LogFactory; import com.google.common.base.Preconditions; +import com.intel.chimera.utils.Utils; /** * Implement the AES-CTR crypto codec using JCE provider. @@ -43,8 +44,8 @@ public class JceAesCtrCryptoCodec extends AesCtrCryptoCodec { private SecureRandom random; public JceAesCtrCryptoCodec(Properties props) { - provider = ChimeraUtils.getJCEProvider(props); - final String secureRandomAlg = ChimeraUtils.getSecureRandomAlg(props); + provider = Utils.getJCEProvider(props); + final String secureRandomAlg = Utils.getSecureRandomAlg(props); try { random = (provider != null) ? SecureRandom.getInstance(secureRandomAlg, provider) : diff --git a/src/main/java/com/intel/chimera/OpensslAesCtrCryptoCodec.java b/src/main/java/com/intel/chimera/OpensslAesCtrCryptoCodec.java index f065f5026..91a4dccaf 100644 --- a/src/main/java/com/intel/chimera/OpensslAesCtrCryptoCodec.java +++ b/src/main/java/com/intel/chimera/OpensslAesCtrCryptoCodec.java @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import com.google.common.base.Preconditions; +import com.intel.chimera.utils.Utils; import com.intel.chimera.utils.ReflectionUtils; /** @@ -46,7 +47,7 @@ public OpensslAesCtrCryptoCodec(Properties props) { throw new RuntimeException(loadingFailureReason); } - final Class klass = ChimeraUtils.getSecureRandomClass(props); + final Class klass = Utils.getSecureRandomClass(props); try { random = ReflectionUtils.newInstance(klass, props); } catch (Exception e) { diff --git a/src/main/java/com/intel/chimera/VERSION b/src/main/java/com/intel/chimera/VERSION deleted file mode 100644 index 9036dc428..000000000 --- a/src/main/java/com/intel/chimera/VERSION +++ /dev/null @@ -1 +0,0 @@ -VERSION=0.0.1 \ No newline at end of file diff --git a/src/main/java/com/intel/chimera/random/OsSecureRandom.java b/src/main/java/com/intel/chimera/random/OsSecureRandom.java index 32d639aed..c068e9af3 100644 --- a/src/main/java/com/intel/chimera/random/OsSecureRandom.java +++ b/src/main/java/com/intel/chimera/random/OsSecureRandom.java @@ -27,7 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.intel.chimera.ChimeraUtils; +import com.intel.chimera.utils.Utils; import com.intel.chimera.utils.IOUtils; /** @@ -61,7 +61,7 @@ private void fillReservoir(int min) { } public OsSecureRandom(Properties props) { - randomDevPath = ChimeraUtils.getRandomDevPath(props); + randomDevPath = Utils.getRandomDevPath(props); File randomDevFile = new File(randomDevPath); try { diff --git a/src/main/java/com/intel/chimera/utils/NativeCodeLoader.java b/src/main/java/com/intel/chimera/utils/NativeCodeLoader.java index c611fd11b..2e3f0f17c 100644 --- a/src/main/java/com/intel/chimera/utils/NativeCodeLoader.java +++ b/src/main/java/com/intel/chimera/utils/NativeCodeLoader.java @@ -30,7 +30,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.intel.chimera.ChimeraUtils; /** * A helper to load the native chimera code i.e. libchimera.so. @@ -78,9 +77,9 @@ public class NativeCodeLoader { static File findNativeLibrary() { // Try to load the library in chimera.lib.path */ - String chimeraNativeLibraryPath = ChimeraUtils + String chimeraNativeLibraryPath = Utils .getChimeraLibPath(); - String chimeraNativeLibraryName = ChimeraUtils + String chimeraNativeLibraryName = Utils .getChimeraLibName(); // Resolve the library file name with a suffix (e.g., dll, .so, etc.) @@ -119,7 +118,7 @@ static File findNativeLibrary() { // Temporary folder for the native lib. Use the value of // chimera.tempdir or java.io.tmpdir - String tempFolder = new File(ChimeraUtils.getChimeraTmpDir()) + String tempFolder = new File(Utils.getChimeraTmpDir()) .getAbsolutePath(); // Extract and load a native library inside the jar file diff --git a/src/main/java/com/intel/chimera/ChimeraUtils.java b/src/main/java/com/intel/chimera/utils/Utils.java similarity index 97% rename from src/main/java/com/intel/chimera/ChimeraUtils.java rename to src/main/java/com/intel/chimera/utils/Utils.java index 03232cb8f..14c04a768 100644 --- a/src/main/java/com/intel/chimera/ChimeraUtils.java +++ b/src/main/java/com/intel/chimera/utils/Utils.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intel.chimera; +package com.intel.chimera.utils; import static com.intel.chimera.ConfigurationKeys.CHIMERA_LIB_NAME_KEY; import static com.intel.chimera.ConfigurationKeys.CHIMERA_LIB_PATH_KEY; @@ -40,10 +40,12 @@ import java.util.Random; import com.google.common.base.Preconditions; +import com.intel.chimera.CipherSuite; +import com.intel.chimera.CryptoCodec; +import com.intel.chimera.UnsupportedCodecException; import com.intel.chimera.random.OsSecureRandom; -import com.intel.chimera.utils.ReflectionUtils; -public class ChimeraUtils { +public class Utils { private static final int MIN_BUFFER_SIZE = 512; static {