Skip to content

Commit

Permalink
Rename ChimeraUtils to Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dianfu committed Nov 11, 2015
1 parent 80a8628 commit afa3d61
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/intel/chimera/CryptoCodec.java
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<Class<? extends CryptoCodec>> getCodecClasses(
Properties props, CipherSuite cipherSuite) {
List<Class<? extends CryptoCodec>> 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.");
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/intel/chimera/CryptoInputStream.java
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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 */
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/intel/chimera/CryptoOutputStream.java
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/intel/chimera/JceAesCtrCryptoCodec.java
Expand Up @@ -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.
Expand All @@ -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) :
Expand Down
Expand Up @@ -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;

/**
Expand All @@ -46,7 +47,7 @@ public OpensslAesCtrCryptoCodec(Properties props) {
throw new RuntimeException(loadingFailureReason);
}

final Class<? extends Random> klass = ChimeraUtils.getSecureRandomClass(props);
final Class<? extends Random> klass = Utils.getSecureRandomClass(props);
try {
random = ReflectionUtils.newInstance(klass, props);
} catch (Exception e) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/intel/chimera/VERSION

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/com/intel/chimera/random/OsSecureRandom.java
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/intel/chimera/utils/NativeCodeLoader.java
Expand Up @@ -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.
Expand Down Expand Up @@ -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.)
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit afa3d61

Please sign in to comment.