Turbine coding standards/format updates
git-svn-id: https://svn.apache.org/repos/asf/turbine/fulcrum/trunk/crypto@1850667 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/fulcrum/crypto/DefaultCryptoService.java b/src/java/org/apache/fulcrum/crypto/DefaultCryptoService.java
index 81c6628..96534e8 100644
--- a/src/java/org/apache/fulcrum/crypto/DefaultCryptoService.java
+++ b/src/java/org/apache/fulcrum/crypto/DefaultCryptoService.java
@@ -70,7 +70,8 @@
* @throws NoSuchAlgorithmException Requested algorithm is not available
*
*/
- public CryptoAlgorithm getCryptoAlgorithm(String algo) throws NoSuchAlgorithmException {
+ public CryptoAlgorithm getCryptoAlgorithm(String algo) throws NoSuchAlgorithmException
+ {
String cryptoClass = (String) algos.get(algo);
CryptoAlgorithm ca = null;
if (cryptoClass == null) {
@@ -98,8 +99,8 @@
* @param conf the configuration
* @throws ConfigurationException if not found
*/
- public void configure(Configuration conf) throws ConfigurationException {
-
+ public void configure(Configuration conf) throws ConfigurationException
+ {
// Initialize the hash and setup default
// Can be overriden by default key from properties
this.algos = new HashMap<>();
@@ -120,14 +121,16 @@
*
* @throws Exception generic exception
*/
- public void initialize() throws Exception {
+ public void initialize() throws Exception
+ {
getLogger().debug("initialize()");
}
/**
* Avalon component lifecycle method
*/
- public void dispose() {
+ public void dispose()
+ {
algos = null;
}
diff --git a/src/java/org/apache/fulcrum/crypto/provider/ClearCrypt.java b/src/java/org/apache/fulcrum/crypto/provider/ClearCrypt.java
index c3efdc2..e237a2c 100644
--- a/src/java/org/apache/fulcrum/crypto/provider/ClearCrypt.java
+++ b/src/java/org/apache/fulcrum/crypto/provider/ClearCrypt.java
@@ -37,7 +37,8 @@
/**
* Constructor
*/
- public ClearCrypt() {
+ public ClearCrypt()
+ {
}
/**
@@ -45,7 +46,8 @@
*
* @param cipher Cipher (ignored)
*/
- public void setCipher(String cipher) {
+ public void setCipher(String cipher)
+ {
/* dummy */
}
@@ -54,7 +56,8 @@
*
* @param seed Seed (ignored)
*/
- public void setSeed(String seed) {
+ public void setSeed(String seed)
+ {
/* dummy */
}
@@ -65,7 +68,8 @@
* @return The encrypted value
* @throws Exception An Exception of the underlying implementation.
*/
- public String encrypt(String value) throws Exception {
+ public String encrypt(String value) throws Exception
+ {
/*
* Ultra-clever implementation. ;-)
*/
diff --git a/src/java/org/apache/fulcrum/crypto/provider/JavaCrypt.java b/src/java/org/apache/fulcrum/crypto/provider/JavaCrypt.java
index 833c5e9..e5a85b6 100644
--- a/src/java/org/apache/fulcrum/crypto/provider/JavaCrypt.java
+++ b/src/java/org/apache/fulcrum/crypto/provider/JavaCrypt.java
@@ -54,7 +54,8 @@
* Constructo
*
*/
- public JavaCrypt() {
+ public JavaCrypt()
+ {
this.cipher = DEFAULT_CIPHER;
}
@@ -68,7 +69,8 @@
* @param cipher The cipher to use.
*
*/
- public void setCipher(String cipher) {
+ public void setCipher(String cipher)
+ {
this.cipher = cipher;
}
@@ -78,7 +80,8 @@
* @param seed Seed (ignored)
*
*/
- public void setSeed(String seed) {
+ public void setSeed(String seed)
+ {
/* dummy */
}
@@ -89,7 +92,8 @@
* @return The encrypted value
* @throws Exception An Exception of the underlying implementation.
*/
- public String encrypt(String value) throws Exception {
+ public String encrypt(String value) throws Exception
+ {
MessageDigest md = MessageDigest.getInstance(cipher);
// We need to use unicode here, to be independent of platform's
diff --git a/src/java/org/apache/fulcrum/crypto/provider/OldJavaCrypt.java b/src/java/org/apache/fulcrum/crypto/provider/OldJavaCrypt.java
index baae850..8ca9445 100644
--- a/src/java/org/apache/fulcrum/crypto/provider/OldJavaCrypt.java
+++ b/src/java/org/apache/fulcrum/crypto/provider/OldJavaCrypt.java
@@ -53,7 +53,8 @@
/**
* Constructor
*/
- public OldJavaCrypt() {
+ public OldJavaCrypt()
+ {
this.cipher = DEFAULT_CIPHER;
}
@@ -67,7 +68,8 @@
* @param cipher The cipher to use.
*
*/
- public void setCipher(String cipher) {
+ public void setCipher(String cipher)
+ {
this.cipher = cipher;
}
@@ -77,7 +79,8 @@
* @param seed Seed (ignored)
*
*/
- public void setSeed(String seed) {
+ public void setSeed(String seed)
+ {
/* dummy */
}
@@ -88,7 +91,8 @@
* @return The encrypted value
* @throws Exception An Exception of the underlying implementation.
*/
- public String encrypt(String value) throws Exception {
+ public String encrypt(String value) throws Exception
+ {
MessageDigest md = MessageDigest.getInstance(cipher);
byte[] digest = md.digest(value.getBytes("UTF-8"));
byte[] base64 = Base64.encodeBase64(digest);
diff --git a/src/java/org/apache/fulcrum/crypto/provider/UnixCrypt.java b/src/java/org/apache/fulcrum/crypto/provider/UnixCrypt.java
index 23ea97e..62b56ca 100644
--- a/src/java/org/apache/fulcrum/crypto/provider/UnixCrypt.java
+++ b/src/java/org/apache/fulcrum/crypto/provider/UnixCrypt.java
@@ -41,7 +41,8 @@
/**
* Constructor
*/
- public UnixCrypt() {
+ public UnixCrypt()
+ {
}
/**
@@ -50,7 +51,8 @@
*
* @param cipher Cipher (ignored)
*/
- public void setCipher(String cipher) {
+ public void setCipher(String cipher)
+ {
/* dummy */
}
@@ -60,7 +62,8 @@
*
* @param seed The seed value to use.
*/
- public void setSeed(String seed) {
+ public void setSeed(String seed)
+ {
this.seed = seed;
}
@@ -71,8 +74,8 @@
* @return The encrypted value
* @throws Exception An Exception of the underlying implementation.
*/
- public String encrypt(String value) throws Exception {
-
+ public String encrypt(String value) throws Exception
+ {
if (seed == null) {
Random randomGenerator = new Random();
int numSaltChars = SALT_CHARS.length;
diff --git a/src/test/org/apache/fulcrum/crypto/CryptoServiceTest.java b/src/test/org/apache/fulcrum/crypto/CryptoServiceTest.java
index 2c44865..708aa7d 100644
--- a/src/test/org/apache/fulcrum/crypto/CryptoServiceTest.java
+++ b/src/test/org/apache/fulcrum/crypto/CryptoServiceTest.java
@@ -86,6 +86,7 @@
assertEquals( output, result, "Encryption failed ");
}
+
@Test
public void testClearCrypt() throws Exception
{
@@ -96,6 +97,7 @@
assertEquals( preDefinedResult, output, "Encryption failed ");
}
+
@Test
@DisplayName("OldJavaCrypt: Truncated base64 from MD5 (Turbine 2.1) Test")
public void testOldJavaCryptMd5() throws Exception
@@ -108,6 +110,7 @@
assertEquals( preDefinedResult, output, "MD5 Encryption failed ");
}
+
@Test
public void testOldJavaCryptSha1() throws Exception
{
@@ -119,6 +122,7 @@
assertEquals( preDefinedResult, output, "SHA1 Encryption failed ");
}
+
@Test
public void testJavaCryptMd5() throws Exception
{
@@ -128,6 +132,7 @@
String output = ca.encrypt(preDefinedInput);
assertEquals( preDefinedResult, output, "MD5 Encryption failed ");
}
+
@Test
public void testJavaCryptSha1() throws Exception
{
@@ -138,6 +143,7 @@
assertEquals( preDefinedResult, output, "SHA1 Encryption failed ");
}
+
@Test
public void testJavaCryptSha256() throws Exception
{