You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sd...@apache.org on 2016/06/24 08:36:17 UTC
[1/2] commons-crypto git commit: CRYPTO-88: ConfigurationKeys
constants could have much shorter names
Repository: commons-crypto
Updated Branches:
refs/heads/master e90580a89 -> 49a264718
CRYPTO-88: ConfigurationKeys constants could have much shorter names
Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/12988811
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/12988811
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/12988811
Branch: refs/heads/master
Commit: 12988811376e69f88e1aec6ac45576c3678b0aa4
Parents: e90580a
Author: Sun Dapeng <sd...@apache.org>
Authored: Fri Jun 24 16:16:39 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Fri Jun 24 16:16:39 2016 +0800
----------------------------------------------------------------------
.../apache/commons/crypto/cipher/JceCipher.java | 6 ++--
.../commons/crypto/conf/ConfigurationKeys.java | 38 ++++++++++----------
.../commons/crypto/examples/RandomExample.java | 2 +-
.../crypto/random/CryptoRandomFactory.java | 8 ++---
.../commons/crypto/random/JavaCryptoRandom.java | 4 +--
.../commons/crypto/random/OsCryptoRandom.java | 6 ++--
.../org/apache/commons/crypto/utils/Utils.java | 32 ++++++++---------
.../crypto/cipher/AbstractCipherTest.java | 2 +-
.../crypto/cipher/CryptoCipherFactoryTest.java | 11 +++---
.../crypto/random/TestJavaCryptoRandom.java | 2 +-
.../crypto/random/TestOpensslCryptoRandom.java | 2 +-
11 files changed, 55 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java b/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
index 7dcd606..6478e3c 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/JceCipher.java
@@ -211,8 +211,8 @@ public class JceCipher implements CryptoCipher {
* @return the jce provider based on the props.
*/
private static String getJCEProvider(Properties props) {
- return props.getProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY) !=
- null ? props.getProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY)
- : System.getProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY);
+ return props.getProperty(ConfigurationKeys.CIPHER_JCE_PROVIDER_KEY) !=
+ null ? props.getProperty(ConfigurationKeys.CIPHER_JCE_PROVIDER_KEY)
+ : System.getProperty(ConfigurationKeys.CIPHER_JCE_PROVIDER_KEY);
}
}
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java b/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java
index d808f0d..580eff5 100644
--- a/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java
+++ b/src/main/java/org/apache/commons/crypto/conf/ConfigurationKeys.java
@@ -32,12 +32,12 @@ public class ConfigurationKeys {
/**
* The filename of configuration file.
*/
- public static final String COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE = CONF_PREFIX
+ public static final String SYSTEM_PROPERTIES_FILE = CONF_PREFIX
+ "properties";
/**
* The configuration key of implementation class for crypto cipher. The
- * values of COMMONS_CRYPTO_CIPHER_CLASSES_KEY can be
+ * values of CIPHER_CLASSES_KEY can be
* "org.apache.commons.crypto.cipher.JceCipher" or
* "org.apache.commons.crypto.cipher.OpensslCipher". Or it can be a comma
* separated list. The "org.apache.commons.crypto.cipher.JceCipher" use jce
@@ -46,47 +46,47 @@ public class ConfigurationKeys {
* implement. Note that for each value,the first value which can be created
* without exception will be used (priority by order).
*/
- public static final String COMMONS_CRYPTO_CIPHER_CLASSES_KEY = CONF_PREFIX
+ public static final String CIPHER_CLASSES_KEY = CONF_PREFIX
+ "cipher.classes";
/**
* The default value for crypto cipher.
*/
- public static final String COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT = OpensslCipher.class
+ public static final String CIPHER_CLASSES_DEFAULT = OpensslCipher.class
.getName();
/**
* The configuration key of the provider class for JCE cipher.
*/
- public static final String COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY = CONF_PREFIX
+ public static final String CIPHER_JCE_PROVIDER_KEY = CONF_PREFIX
+ "cipher.jce.provider";
// security random related configuration keys
/**
* The configuration key of the file path for secure random device.
*/
- public static final String COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_KEY = CONF_PREFIX
+ public static final String SECURE_RANDOM_DEVICE_FILE_PATH_KEY = CONF_PREFIX
+ "secure.random.device.file.path";
/**
* The default value of the file path for secure random device.
*/
- public static final String COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT = "/dev/urandom";
+ public static final String SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT = "/dev/urandom";
/**
* The configuration key of the algorithm of secure random.
*/
- public static final String COMMONS_CRYPTO_SECURE_RANDOM_JAVA_ALGORITHM_KEY = CONF_PREFIX
+ public static final String SECURE_RANDOM_JAVA_ALGORITHM_KEY = CONF_PREFIX
+ "secure.random.java.algorithm";
/**
* The default value of the algorithm of secure random.
*/
- public static final String COMMONS_CRYPTO_SECURE_RANDOM_JAVA_ALGORITHM_DEFAULT = "SHA1PRNG";
+ public static final String SECURE_RANDOM_JAVA_ALGORITHM_DEFAULT = "SHA1PRNG";
/**
* The configuration key of the implementation class for secure random. The
- * values of COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY can be
+ * values of SECURE_RANDOM_CLASSES_KEY can be
* "org.apache.commons.crypto.random.JavaCryptoRandom" or
* "org.apache.commons.crypto.random.OpensslCryptoRandom". Or it takes a
* comma separated list. The
@@ -96,52 +96,50 @@ public class ConfigurationKeys {
* openssl to implement. Note that for each value,the first value which can
* be created without exception will be used (priority by order).
*/
- public static final String COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY = CONF_PREFIX
+ public static final String SECURE_RANDOM_CLASSES_KEY = CONF_PREFIX
+ "secure.random.classes";
/**
* The configuration key of the buffer size for stream.
*/
- public static final String COMMONS_CRYPTO_STREAM_BUFFER_SIZE_KEY = CONF_PREFIX
+ public static final String STREAM_BUFFER_SIZE_KEY = CONF_PREFIX
+ "stream.buffer.size";
// stream related configuration keys
/**
* The default value of the buffer size for stream.
*/
- public static final int COMMONS_CRYPTO_STREAM_BUFFER_SIZE_DEFAULT = 8192;
+ public static final int STREAM_BUFFER_SIZE_DEFAULT = 8192;
// native lib related configuration keys
/**
* The configuration key of the path for loading crypto library.
*/
- public static final String COMMONS_CRYPTO_LIB_PATH_KEY = CONF_PREFIX
+ public static final String LIB_PATH_KEY = CONF_PREFIX
+ "lib.path";
/**
* The configuration key of the file name for loading crypto library.
*/
- public static final String COMMONS_CRYPTO_LIB_NAME_KEY = CONF_PREFIX
+ public static final String LIB_NAME_KEY = CONF_PREFIX
+ "lib.name";
/**
* The configuration key of temp directory for extracting crypto library.
*/
- public static final String COMMONS_CRYPTO_LIB_TEMPDIR_KEY = CONF_PREFIX
+ public static final String LIB_TEMPDIR_KEY = CONF_PREFIX
+ "lib.tempdir";
/**
* The configuration key of enable fallback on native failed.
*/
- public static final String
- COMMONS_CRYPTO_ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY = CONF_PREFIX +
+ public static final String ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY = CONF_PREFIX +
"enable.fallback";
/**
* The default value of enable fallback on native failed.
*/
- public static final boolean
- COMMONS_CRYPTO_ENABLE_FALLBACK_ON_NATIVE_FAILED_DEFAULT = true;
+ public static final boolean ENABLE_FALLBACK_ON_NATIVE_FAILED_DEFAULT = true;
/**
* The private constructor of {@Link ConfigurationKeys}.
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/RandomExample.java b/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
index 09f6ea3..a350d7f 100644
--- a/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
@@ -33,7 +33,7 @@ public class RandomExample {
byte[] key = new byte[16];
byte[] iv = new byte[16];
Properties properties = new Properties();
- properties.put(ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY,
+ properties.put(ConfigurationKeys.SECURE_RANDOM_CLASSES_KEY,
"org.apache.commons.crypto.random.OpensslCryptoRandom"); // TODO replace with alias
//Gets the 'CryptoRandom' instance.
CryptoRandom random = CryptoRandomFactory.getCryptoRandom(properties);
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
index a9d0ce2..4becf83 100644
--- a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
+++ b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
@@ -22,7 +22,7 @@ import java.util.Properties;
import org.apache.commons.crypto.utils.ReflectionUtils;
import org.apache.commons.crypto.utils.Utils;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY;
+import static org.apache.commons.crypto.conf.ConfigurationKeys.SECURE_RANDOM_CLASSES_KEY;
/**
* This is the factory class used for {@link CryptoRandom}.
@@ -37,7 +37,7 @@ public class CryptoRandomFactory {
/**
* Gets a CryptoRandom instance for specified props.
- * Uses the COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY from the provided
+ * Uses the SECURE_RANDOM_CLASSES_KEY from the provided
* properties.
* If it is not set, then it checks the System properties.
* Failing that, it defaults to {@link JavaCryptoRandom}
@@ -52,10 +52,10 @@ public class CryptoRandomFactory {
public static CryptoRandom getCryptoRandom(Properties props)
throws GeneralSecurityException {
String cryptoRandomClasses = props
- .getProperty(COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY);
+ .getProperty(SECURE_RANDOM_CLASSES_KEY);
if (cryptoRandomClasses == null) {
cryptoRandomClasses = System
- .getProperty(COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY);
+ .getProperty(SECURE_RANDOM_CLASSES_KEY);
}
StringBuilder errorMessage = new StringBuilder();
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java
index 390f381..210c181 100644
--- a/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/random/JavaCryptoRandom.java
@@ -42,8 +42,8 @@ public class JavaCryptoRandom implements CryptoRandom {
instance = SecureRandom
.getInstance(properties
.getProperty(
- ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_JAVA_ALGORITHM_KEY,
- ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_JAVA_ALGORITHM_DEFAULT));
+ ConfigurationKeys.SECURE_RANDOM_JAVA_ALGORITHM_KEY,
+ ConfigurationKeys.SECURE_RANDOM_JAVA_ALGORITHM_DEFAULT));
}
/**
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
index d105e56..feb1f5b 100644
--- a/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
@@ -142,11 +142,11 @@ public class OsCryptoRandom extends Random implements CryptoRandom {
*/
private static String getRandomDevPath(Properties props) {
String devPath = props
- .getProperty(ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_KEY);
+ .getProperty(ConfigurationKeys.SECURE_RANDOM_DEVICE_FILE_PATH_KEY);
if (devPath == null) {
devPath = System.getProperty(
- ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_KEY,
- ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT);
+ ConfigurationKeys.SECURE_RANDOM_DEVICE_FILE_PATH_KEY,
+ ConfigurationKeys.SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT);
}
return devPath;
}
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/main/java/org/apache/commons/crypto/utils/Utils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/utils/Utils.java b/src/main/java/org/apache/commons/crypto/utils/Utils.java
index fc1896d..79045bd 100644
--- a/src/main/java/org/apache/commons/crypto/utils/Utils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/Utils.java
@@ -58,12 +58,12 @@ public final class Utils {
/**
* loads system properties when configuration file of the name
- * {@link ConfigurationKeys#COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE} is found.
+ * {@link ConfigurationKeys#SYSTEM_PROPERTIES_FILE} is found.
*/
private static void loadSystemProperties() {
try {
InputStream is = Thread.currentThread().getContextClassLoader()
- .getResourceAsStream(ConfigurationKeys.COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE);
+ .getResourceAsStream(ConfigurationKeys.SYSTEM_PROPERTIES_FILE);
if (is == null) {
return; // no configuration file is found
@@ -81,7 +81,7 @@ public final class Utils {
}
} catch (Throwable ex) {
System.err.println("Could not load '"
- + ConfigurationKeys.COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE
+ + ConfigurationKeys.SYSTEM_PROPERTIES_FILE
+ "' from classpath: " + ex.toString());
}
}
@@ -125,13 +125,13 @@ public final class Utils {
* */
public static int getBufferSize(Properties props) {
String bufferSizeStr = props
- .getProperty(ConfigurationKeys.COMMONS_CRYPTO_STREAM_BUFFER_SIZE_KEY);
+ .getProperty(ConfigurationKeys.STREAM_BUFFER_SIZE_KEY);
if (bufferSizeStr == null || bufferSizeStr.isEmpty()) {
bufferSizeStr = System
- .getProperty(ConfigurationKeys.COMMONS_CRYPTO_STREAM_BUFFER_SIZE_KEY);
+ .getProperty(ConfigurationKeys.STREAM_BUFFER_SIZE_KEY);
}
if (bufferSizeStr == null || bufferSizeStr.isEmpty()) {
- return ConfigurationKeys.COMMONS_CRYPTO_STREAM_BUFFER_SIZE_DEFAULT;
+ return ConfigurationKeys.STREAM_BUFFER_SIZE_DEFAULT;
}
return Integer.parseInt(bufferSizeStr);
}
@@ -144,13 +144,13 @@ public final class Utils {
* @return the cipher class based on the props.
*/
public static String getCipherClassString(Properties props) {
- final String configName = ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY;
+ final String configName = ConfigurationKeys.CIPHER_CLASSES_KEY;
String cipherClassString = props.getProperty(configName) != null ? props
- .getProperty(configName, ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT)
+ .getProperty(configName, ConfigurationKeys.CIPHER_CLASSES_DEFAULT)
: System.getProperty(configName,
- ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT);
+ ConfigurationKeys.CIPHER_CLASSES_DEFAULT);
if (cipherClassString.isEmpty()) {
- cipherClassString = ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT;
+ cipherClassString = ConfigurationKeys.CIPHER_CLASSES_DEFAULT;
}
return cipherClassString;
}
@@ -161,7 +161,7 @@ public final class Utils {
* @return the path of native library.
*/
public static String getLibPath() {
- return System.getProperty(ConfigurationKeys.COMMONS_CRYPTO_LIB_PATH_KEY);
+ return System.getProperty(ConfigurationKeys.LIB_PATH_KEY);
}
/**
@@ -170,7 +170,7 @@ public final class Utils {
* @return the file name of native library.
*/
public static String getLibName() {
- return System.getProperty(ConfigurationKeys.COMMONS_CRYPTO_LIB_NAME_KEY);
+ return System.getProperty(ConfigurationKeys.LIB_NAME_KEY);
}
/**
@@ -179,7 +179,7 @@ public final class Utils {
* @return the temp directory.
*/
public static String getTmpDir() {
- return System.getProperty(ConfigurationKeys.COMMONS_CRYPTO_LIB_TEMPDIR_KEY,
+ return System.getProperty(ConfigurationKeys.LIB_TEMPDIR_KEY,
System.getProperty("java.io.tmpdir"));
}
@@ -364,14 +364,14 @@ public final class Utils {
*/
public static boolean isFallbackEnabled(Properties props) {
String enableFallback = props.getProperty(ConfigurationKeys.
- COMMONS_CRYPTO_ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY);
+ ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY);
if (enableFallback == null || enableFallback.isEmpty()) {
enableFallback = System.getProperty(ConfigurationKeys.
- COMMONS_CRYPTO_ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY);
+ ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY);
}
if (enableFallback == null || enableFallback.isEmpty()) {
return ConfigurationKeys
- .COMMONS_CRYPTO_ENABLE_FALLBACK_ON_NATIVE_FAILED_DEFAULT;
+ .ENABLE_FALLBACK_ON_NATIVE_FAILED_DEFAULT;
}
return Boolean.valueOf(enableFallback);
}
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
index ee69a06..07fc53e 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/AbstractCipherTest.java
@@ -57,7 +57,7 @@ public abstract class AbstractCipherTest {
Utils.checkNotNull(cipherClass);
Utils.checkNotNull(transformations);
props = new Properties();
- props.setProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY,
+ props.setProperty(ConfigurationKeys.CIPHER_CLASSES_KEY,
cipherClass);
}
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
index 0adf826..1776b4c 100644
--- a/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
+++ b/src/test/java/org/apache/commons/crypto/cipher/CryptoCipherFactoryTest.java
@@ -38,7 +38,7 @@ public class CryptoCipherFactoryTest {
public void testEmptyCipher() throws GeneralSecurityException {
Properties properties = new Properties();
properties.setProperty(
- ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY, "");
+ ConfigurationKeys.CIPHER_CLASSES_KEY, "");
CryptoCipher defaultCipher = CryptoCipherFactory.getInstance(
"AES/CBC/NoPadding", properties);
Assert.assertEquals(OpensslCipher.class.getName(), defaultCipher
@@ -48,7 +48,7 @@ public class CryptoCipherFactoryTest {
@Test
public void testInvalidCipher() throws GeneralSecurityException {
Properties properties = new Properties();
- properties.setProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY,
+ properties.setProperty(ConfigurationKeys.CIPHER_CLASSES_KEY,
"InvalidCipherName");
CryptoCipher defaultCipher = CryptoCipherFactory.getInstance(
"AES/CBC/NoPadding", properties);
@@ -59,11 +59,10 @@ public class CryptoCipherFactoryTest {
@Test(expected = GeneralSecurityException.class)
public void testDisableFallback() throws GeneralSecurityException {
Properties properties = new Properties();
- properties.setProperty(
- ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY,
- "InvalidCipherName");
+ properties.setProperty(ConfigurationKeys.CIPHER_CLASSES_KEY,
+ "InvalidCipherName");
properties.setProperty(ConfigurationKeys
- .COMMONS_CRYPTO_ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY, "false");
+ .ENABLE_FALLBACK_ON_NATIVE_FAILED_KEY, "false");
CryptoCipherFactory.getInstance("AES/CBC/NoPadding", properties);
}
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/test/java/org/apache/commons/crypto/random/TestJavaCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/TestJavaCryptoRandom.java b/src/test/java/org/apache/commons/crypto/random/TestJavaCryptoRandom.java
index e8080bd..ba2681f 100644
--- a/src/test/java/org/apache/commons/crypto/random/TestJavaCryptoRandom.java
+++ b/src/test/java/org/apache/commons/crypto/random/TestJavaCryptoRandom.java
@@ -29,7 +29,7 @@ public class TestJavaCryptoRandom extends AbstractRandomTest {
public CryptoRandom getCryptoRandom() throws GeneralSecurityException {
Properties props = new Properties();
props.setProperty(
- ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY,
+ ConfigurationKeys.SECURE_RANDOM_CLASSES_KEY,
JavaCryptoRandom.class.getName());
CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props);
if (!(random instanceof JavaCryptoRandom)) {
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/12988811/src/test/java/org/apache/commons/crypto/random/TestOpensslCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/crypto/random/TestOpensslCryptoRandom.java b/src/test/java/org/apache/commons/crypto/random/TestOpensslCryptoRandom.java
index c14c6f4..f6d587d 100644
--- a/src/test/java/org/apache/commons/crypto/random/TestOpensslCryptoRandom.java
+++ b/src/test/java/org/apache/commons/crypto/random/TestOpensslCryptoRandom.java
@@ -29,7 +29,7 @@ public class TestOpensslCryptoRandom extends AbstractRandomTest {
public CryptoRandom getCryptoRandom() throws GeneralSecurityException {
Properties props = new Properties();
props.setProperty(
- ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_CLASSES_KEY,
+ ConfigurationKeys.SECURE_RANDOM_CLASSES_KEY,
OpensslCryptoRandom.class.getName());
CryptoRandom random = CryptoRandomFactory.getCryptoRandom(props);
if (!(random instanceof OpensslCryptoRandom)) {
[2/2] commons-crypto git commit: Fix check style
Posted by sd...@apache.org.
Fix check style
Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/49a26471
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/49a26471
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/49a26471
Branch: refs/heads/master
Commit: 49a264718f4511ce272260082315e223d1a4615c
Parents: 1298881
Author: Sun Dapeng <sd...@apache.org>
Authored: Fri Jun 24 16:32:08 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Fri Jun 24 16:32:08 2016 +0800
----------------------------------------------------------------------
.../commons/crypto/cipher/OpensslCipher.java | 2 +-
.../crypto/examples/CipherByteArrayExample.java | 12 +++++++++++
.../examples/CipherByteBufferExample.java | 18 ++++++++++++++++
.../commons/crypto/examples/RandomExample.java | 7 +++++++
.../commons/crypto/examples/StreamExample.java | 12 +++++++++++
.../commons/crypto/examples/package-info.java | 22 ++++++++++++++++++++
.../org/apache/commons/crypto/package-info.java | 22 ++++++++++++++++++++
.../commons/crypto/utils/package-info.java | 2 +-
8 files changed, 95 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/49a26471/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java b/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
index 1cfd3e8..ab088eb 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpensslCipher.java
@@ -50,7 +50,7 @@ public class OpensslCipher implements CryptoCipher {
* @param transformation transformation for OpenSSL cipher
* @throws GeneralSecurityException if OpenSSL cipher initialize failed
*/
- public OpensslCipher(Properties props, String transformation)
+ public OpensslCipher(Properties props, String transformation) // NOPMD
throws GeneralSecurityException {
this.transformation = transformation;
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/49a26471/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java b/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java
index a0a6ea0..e90a876 100644
--- a/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/CipherByteArrayExample.java
@@ -30,10 +30,22 @@ import org.apache.commons.crypto.utils.Utils;
public class CipherByteArrayExample {
+ /**
+ * Converts String to UTF8 bytes
+ *
+ * @param input the input string
+ * @return UTF8 bytes
+ */
private static byte[] getUTF8Bytes(String input) {
return input.getBytes(StandardCharsets.UTF_8);
}
+ /**
+ * Main method
+ *
+ * @param args args of main
+ * @throws Exception when encryption/decryption failed
+ */
public static void main(String[] args) throws Exception {
final SecretKeySpec key = new SecretKeySpec(getUTF8Bytes("1234567890123456"),"AES");
final IvParameterSpec iv = new IvParameterSpec(getUTF8Bytes("1234567890123456"));
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/49a26471/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java b/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java
index e614a6c..d804975 100644
--- a/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/CipherByteBufferExample.java
@@ -31,10 +31,22 @@ import org.apache.commons.crypto.utils.Utils;
public class CipherByteBufferExample {
+ /**
+ * Converts String to UTF8 bytes
+ *
+ * @param input the input string
+ * @return UTF8 bytes
+ */
private static byte[] getUTF8Bytes(String input) {
return input.getBytes(StandardCharsets.UTF_8);
}
+ /**
+ * Converts ByteBuffer to String
+ *
+ * @param buffer input byte buffer
+ * @return the converted string
+ */
private static String asString(ByteBuffer buffer) {
final ByteBuffer copy = buffer.duplicate();
final byte[] bytes = new byte[Math.min(copy.remaining(),50)];
@@ -42,6 +54,12 @@ public class CipherByteBufferExample {
return new String(bytes, StandardCharsets.UTF_8);
}
+ /**
+ * Main method
+ *
+ * @param args args of main
+ * @throws Exception when encryption/decryption failed
+ */
public static void main(String[] args) throws Exception {
final SecretKeySpec key = new SecretKeySpec(getUTF8Bytes("1234567890123456"), "AES");
final IvParameterSpec iv = new IvParameterSpec(getUTF8Bytes("1234567890123456"));
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/49a26471/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/RandomExample.java b/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
index a350d7f..7e0c220 100644
--- a/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/RandomExample.java
@@ -28,6 +28,13 @@ import org.apache.commons.crypto.random.CryptoRandomFactory;
public class RandomExample {
+ /**
+ * Main method
+ *
+ * @param args args of main
+ * @throws GeneralSecurityException when encryption/decryption failed
+ * @throws IOException when io failed
+ */
public static void main(String []args) throws GeneralSecurityException, IOException {
//Constructs a byte array to store random data.
byte[] key = new byte[16];
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/49a26471/src/main/java/org/apache/commons/crypto/examples/StreamExample.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/StreamExample.java b/src/main/java/org/apache/commons/crypto/examples/StreamExample.java
index 8904cb1..b92ffca 100644
--- a/src/main/java/org/apache/commons/crypto/examples/StreamExample.java
+++ b/src/main/java/org/apache/commons/crypto/examples/StreamExample.java
@@ -36,10 +36,22 @@ import org.apache.commons.crypto.stream.CryptoOutputStream;
*/
public class StreamExample {
+ /**
+ * Converts String to UTF8 bytes
+ *
+ * @param input the input string
+ * @return UTF8 bytes
+ */
private static byte[] getUTF8Bytes(String input) {
return input.getBytes(StandardCharsets.UTF_8);
}
+ /**
+ * Main method
+ *
+ * @param args args of main
+ * @throws IOException when stream encryption/decryption failed
+ */
public static void main(String []args) throws IOException {
final SecretKeySpec key = new SecretKeySpec(getUTF8Bytes("1234567890123456"),"AES");
final IvParameterSpec iv = new IvParameterSpec(getUTF8Bytes("1234567890123456"));
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/49a26471/src/main/java/org/apache/commons/crypto/examples/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/examples/package-info.java b/src/main/java/org/apache/commons/crypto/examples/package-info.java
new file mode 100644
index 0000000..6f9c541
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/examples/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Example classes
+ */
+package org.apache.commons.crypto.examples;
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/49a26471/src/main/java/org/apache/commons/crypto/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/package-info.java b/src/main/java/org/apache/commons/crypto/package-info.java
new file mode 100644
index 0000000..f7434c1
--- /dev/null
+++ b/src/main/java/org/apache/commons/crypto/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Crypto classes
+ */
+package org.apache.commons.crypto;
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/49a26471/src/main/java/org/apache/commons/crypto/utils/package-info.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/utils/package-info.java b/src/main/java/org/apache/commons/crypto/utils/package-info.java
index 20785f2..060117e 100644
--- a/src/main/java/org/apache/commons/crypto/utils/package-info.java
+++ b/src/main/java/org/apache/commons/crypto/utils/package-info.java
@@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
/**
* Utils classes
*/
package org.apache.commons.crypto.utils;
-