Make SonarQube happier with the source code

This commit is contained in:
Marko Zivanovic
2015-03-11 11:07:33 +01:00
parent cabfc67b99
commit 10be4bfd8e
8 changed files with 81 additions and 18 deletions
+4
View File
@@ -121,4 +121,8 @@
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<prerequisites>
<maven>3.0.4</maven>
</prerequisites>
</project>
@@ -33,7 +33,10 @@ import java.util.Map.Entry;
*/
public class Main {
public static void main(String args[]) {
private Main() {
}
public static void main(String[] args) {
JCommander jc = new JCommander();
Map<String, Runnable> commands = new HashMap<>();
Map<String, String[]> aliases = new HashMap<>();
@@ -55,7 +58,7 @@ public class Main {
jc.usage();
}
} catch (RuntimeException ex) {
System.err.println(ex.getMessage());
System.err.println("ERROR: " + ex.getMessage());
}
}
+6 -2
View File
@@ -39,8 +39,8 @@
<connection>scm:git:git@github.com:zmarko/jPasswordObfuscator.git</connection>
<developerConnection>scm:git:git@github.com:zmarko/jPasswordObfuscator.git</developerConnection>
<url>git@github.com:zmarko/jPasswordObfuscator.git</url>
<tag>HEAD</tag>
</scm>
<tag>HEAD</tag>
</scm>
<dependencies>
<dependency>
@@ -139,4 +139,8 @@
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<prerequisites>
<maven>3.0.4</maven>
</prerequisites>
</project>
@@ -42,7 +42,7 @@ public final class JPasswordObfuscator {
* Obfuscate data using supplied master key and current algorithm version.
*
* @param masterKey master key to use for obfuscation
* @param data data to obfuscate
* @param data data to obfuscate
*
* @return string containing obfuscated data; use {@link #deObfuscate} to get secret data from this string
*/
@@ -54,8 +54,8 @@ public final class JPasswordObfuscator {
* Obfuscate data using supplied master key and algorithm version.
*
* @param masterKey master key to use for obfuscation
* @param data data to obfuscate
* @param version obfuscation algorithm version to use
* @param data data to obfuscate
* @param version obfuscation algorithm version to use
*
* @return string containing obfuscated data; use {@link #deObfuscate} to get secret data from this string
*/
@@ -73,7 +73,7 @@ public final class JPasswordObfuscator {
/**
* De-obfuscate string generated with {@link #obfuscate} method.
*
* @param masterKey master key to use for de-obfuscation; must match the key used for obfuscation
* @param masterKey master key to use for de-obfuscation; must match the key used for obfuscation
* @param obfuscatedString obfuscated string generated using one of {@link #obfuscate} methods
*
* @return original, de-obfuscated data
@@ -82,11 +82,11 @@ public final class JPasswordObfuscator {
Objects.requireNonNull(masterKey);
Objects.requireNonNull(obfuscatedString);
ObfuscatedData ob = ObfuscatedData.fromString(obfuscatedString);
switch (ob.version) {
switch (ob.getVersion()) {
case 1:
return v1Obfuscator.deObfuscate(masterKey, ob);
default:
throw new IllegalArgumentException("Unsupported version: " + ob.version);
throw new IllegalArgumentException("Unsupported version: " + ob.getVersion());
}
}
@@ -23,6 +23,7 @@
*/
package rs.in.zivanovic.obfuscator.impl;
import java.util.Arrays;
import org.bouncycastle.util.encoders.Base64;
/**
@@ -31,14 +32,14 @@ import org.bouncycastle.util.encoders.Base64;
public class ObfuscatedData {
private static final String SIGNATURE = "rizobf";
public final int version;
public final byte[] salt;
public final byte[] cipherText;
private final int version;
private final byte[] salt;
private final byte[] cipherText;
public ObfuscatedData(int version, byte[] salt, byte[] cipherText) {
this.version = version;
this.salt = salt;
this.cipherText = cipherText;
this.salt = Arrays.copyOf(salt, salt.length);
this.cipherText = Arrays.copyOf(cipherText, cipherText.length);
}
@Override
@@ -58,4 +59,16 @@ public class ObfuscatedData {
return new ObfuscatedData(Integer.parseInt(parts[2]), Base64.decode(parts[3]), Base64.decode(parts[4]));
}
public int getVersion() {
return version;
}
public byte[] getSalt() {
return salt;
}
public byte[] getCipherText() {
return cipherText;
}
}
@@ -0,0 +1,35 @@
/*
* The MIT License
*
* Copyright 2015 Marko Zivanovic <marko@zivanovic.in.rs>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package rs.in.zivanovic.obfuscator.impl;
/**
* Obfuscation / de-obfuscation -related exceptions.
*/
public class ObfuscatorException extends RuntimeException {
public ObfuscatorException(Throwable cause) {
super(cause);
}
}
@@ -55,16 +55,16 @@ public class PBEObfuscatorImpl implements Obfuscator {
byte[] cipher = crypto(Cipher.ENCRYPT_MODE, data, masterKey, salt);
return new ObfuscatedData(version, salt, cipher);
} catch (GeneralSecurityException ex) {
throw new RuntimeException(ex);
throw new ObfuscatorException(ex);
}
}
@Override
public byte[] deObfuscate(char[] masterKey, ObfuscatedData ob) {
try {
return crypto(Cipher.DECRYPT_MODE, ob.cipherText, masterKey, ob.salt);
return crypto(Cipher.DECRYPT_MODE, ob.getCipherText(), masterKey, ob.getSalt());
} catch (GeneralSecurityException ex) {
throw new RuntimeException(ex);
throw new ObfuscatorException(ex);
}
}
+4
View File
@@ -46,4 +46,8 @@
<module>jPasswordObfuscator-bin</module>
</modules>
<prerequisites>
<maven>3.0.4</maven>
</prerequisites>
</project>