cleanup many inspection things

This commit is contained in:
Lars Gohlke 2013-02-17 23:51:59 +01:00
parent f42c0460f0
commit eabe5b5902
14 changed files with 76 additions and 180 deletions

View file

@ -104,7 +104,7 @@ public class EncFSShell {
System.out.print("No EncFS volume found at '" + path
+ "' would you like to create it? [Yes/No]: ");
String response = null;
String response;
try {
response = br.readLine();
} catch (IOException e) {
@ -494,7 +494,7 @@ public class EncFSShell {
dstPath = EncFSVolume.combinePath(curDir, pathArray[1]);
}
boolean result = false;
boolean result;
try {
result = volume.movePath(srcPath, dstPath,
new EncFSShellProgressListener());
@ -555,7 +555,7 @@ public class EncFSShell {
.getPath();
// Need to convert destination path to an absolute path
String dstPath = null;
String dstPath;
if (pathArray[1].startsWith(EncFSVolume.PATH_SEPARATOR)) {
// Already an absolute path
dstPath = pathArray[1];
@ -564,7 +564,7 @@ public class EncFSShell {
dstPath = EncFSVolume.combinePath(curDir, pathArray[1]);
}
boolean result = false;
boolean result;
try {
result = volume.copyPath(srcPath, dstPath,
new EncFSShellProgressListener());
@ -604,7 +604,7 @@ public class EncFSShell {
}
// regular directory path, find and cd into it
ArrayList<EncFSFile> pathList = null;
ArrayList<EncFSFile> pathList;
try {
pathList = getPath(dirPath);
} catch (FileNotFoundException e) {
@ -623,7 +623,7 @@ public class EncFSShell {
}
/*
* Current directory goes into the stack also Special
* Current directory goes into the stack also Special
* handling for absolute paths
*/
if (dirPath.startsWith(EncFSVolume.PATH_SEPARATOR)) {
@ -651,7 +651,7 @@ public class EncFSShell {
}
String filePath = readFileName(st);
// Find and print file
ArrayList<EncFSFile> pathList = null;
ArrayList<EncFSFile> pathList;
try {
pathList = getPath(filePath);
} catch (FileNotFoundException e) {

View file

@ -11,7 +11,7 @@ public class BlockFilenameDecryptionStrategy extends NotNullFilenameDecryptionSt
super(volume, volumePath, EncFSAlgorithm.BLOCK);
}
protected byte[] decryptConcrete(EncFSVolume volume, byte[] chainIv, byte[] macBytes, byte[] encFileName, byte[] fileIv) throws EncFSCorruptDataException {
protected byte[] decryptConcrete(EncFSVolume volume, byte[] encFileName, byte[] fileIv) throws EncFSCorruptDataException {
try {
return BlockCryptography.blockDecode(volume, fileIv, encFileName);
} catch (InvalidAlgorithmParameterException e) {

View file

@ -769,7 +769,7 @@ public final class EncFSBase64 {
if (destination == null) {
throw new NullPointerException("Destination array was null.");
}
if (0 < 0 || 0 + 3 >= source.length) {
if (3 >= source.length) {
throw new IllegalArgumentException(
String.format(
"Source array with length %d cannot have offset of %d and still process four bytes.",
@ -785,28 +785,28 @@ public final class EncFSBase64 {
byte[] DECODABET = getDecodabet(options);
// Example: Dk==
if (source[0 + 2] == EQUALS_SIGN) {
if (source[2] == EQUALS_SIGN) {
// Two ways to do the same thing. Don't know which way I like best.
// int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6
// )
// | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 );
int outBuff = ((DECODABET[source[0]] & 0xFF) << 18)
| ((DECODABET[source[0 + 1]] & 0xFF) << 12);
| ((DECODABET[source[1]] & 0xFF) << 12);
destination[destOffset] = (byte) (outBuff >>> 16);
return 1;
}
// Example: DkL=
else if (source[0 + 3] == EQUALS_SIGN) {
else if (source[3] == EQUALS_SIGN) {
// Two ways to do the same thing. Don't know which way I like best.
// int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6
// )
// | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )
// | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 );
int outBuff = ((DECODABET[source[0]] & 0xFF) << 18)
| ((DECODABET[source[0 + 1]] & 0xFF) << 12)
| ((DECODABET[source[0 + 2]] & 0xFF) << 6);
| ((DECODABET[source[1]] & 0xFF) << 12)
| ((DECODABET[source[2]] & 0xFF) << 6);
destination[destOffset] = (byte) (outBuff >>> 16);
destination[destOffset + 1] = (byte) (outBuff >>> 8);
@ -822,9 +822,9 @@ public final class EncFSBase64 {
// | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 )
// | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 );
int outBuff = ((DECODABET[source[0]] & 0xFF) << 18)
| ((DECODABET[source[0 + 1]] & 0xFF) << 12)
| ((DECODABET[source[0 + 2]] & 0xFF) << 6)
| ((DECODABET[source[0 + 3]] & 0xFF));
| ((DECODABET[source[1]] & 0xFF) << 12)
| ((DECODABET[source[2]] & 0xFF) << 6)
| ((DECODABET[source[3]] & 0xFF));
destination[destOffset] = (byte) (outBuff >> 16);
destination[destOffset + 1] = (byte) (outBuff >> 8);
@ -870,7 +870,7 @@ public final class EncFSBase64 {
if (source == null) {
throw new NullPointerException("Cannot decode null source array.");
}
if (0 < 0 || 0 + len > source.length) {
if (len > source.length) {
throw new IllegalArgumentException(
String.format(
"Source array with length %d cannot have offset of %d and process %d bytes.",
@ -895,7 +895,7 @@ public final class EncFSBase64 {
// white space
int b4Posn = 0; // Keep track of four byte input buffer
for (int i = 0; i < 0 + len; i++) { // Loop through source
for (int i = 0; i < len; i++) { // Loop through source
// Special value from DECODABET
byte sbiDecode = DECODABET[source[i] & 0xFF];
@ -986,7 +986,7 @@ public final class EncFSBase64 {
bais = new java.io.ByteArrayInputStream(bytes);
gzis = new java.util.zip.GZIPInputStream(bais);
int length = 0;
int length;
while ((length = gzis.read(buffer)) >= 0) {
baos.write(buffer, 0, length);
}
@ -1247,10 +1247,10 @@ public final class EncFSBase64 {
// Else decoding
else {
byte[] b4 = new byte[4];
int i = 0;
int i;
for (i = 0; i < 4; i++) {
// Read four "meaningful" bytes:
int b = 0;
int b;
do {
b = in.read();
} while (b >= 0

View file

@ -110,9 +110,7 @@ public class EncFSConfigParser {
* @return An EncFSConfig object containing the configuration data
* interpreted from the given file.
*/
public static EncFSConfig parseFile(InputStream inputStream)
throws ParserConfigurationException, SAXException, IOException,
EncFSInvalidConfigException, EncFSUnsupportedException {
public static EncFSConfig parseFile(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException, EncFSInvalidConfigException {
EncFSConfig config = EncFSConfigFactory.createDefault();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

View file

@ -58,8 +58,7 @@ public class EncFSConfigWriter {
}
// Create config file contents from a given EncFSConfig / password
private static String createConfigFileContents(EncFSConfig config,
String password) {
private static String createConfigFileContents(EncFSConfig config) {
// XXX: This implementation is pretty horrible, but it works :)
String result = "";
@ -140,9 +139,7 @@ public class EncFSConfigWriter {
* @param config Object encapsulating configuration to write
* @param password Volume password to encode into the config file
*/
public static void writeConfig(EncFSFileProvider fileProvider,
EncFSConfig config, String password)
throws EncFSUnsupportedException, IOException {
public static void writeConfig(EncFSFileProvider fileProvider, EncFSConfig config, String password) throws EncFSUnsupportedException, IOException {
String configFileName = fileProvider.getFilesystemRootPath()
+ EncFSVolume.CONFIG_FILE_NAME;
@ -150,10 +147,9 @@ public class EncFSConfigWriter {
throw new EncFSUnsupportedException("Config file already exists");
}
String configFileContents = createConfigFileContents(config, password);
String configFileContents = createConfigFileContents(config);
OutputStream os = fileProvider.openOutputStream(configFileName,
configFileContents.length());
OutputStream os = fileProvider.openOutputStream(configFileName, configFileContents.length());
os.write(configFileContents.getBytes());
os.close();

View file

@ -179,10 +179,8 @@ public class EncFSFile {
/**
* List files/directory names contained by the directory represented by this
* EncFSFile object.
*
* @return null if not a directory, array of String names otherwise
*/
public String[] list() throws EncFSCorruptDataException, EncFSChecksumException, IOException, IllegalAccessException {
public String[] list() throws IOException {
EncFSFile[] files = listFiles();
String[] fileNames = null;

View file

@ -58,9 +58,9 @@ public class EncFSFileInfo {
public EncFSFileInfo(String name, String parentPath, boolean directory,
long lastModified, long size, boolean readable, boolean writable,
boolean executable) {
if (name.startsWith(EncFSVolume.PATH_SEPARATOR)
&& (name.equals(EncFSVolume.ROOT_PATH) == false))
if (name.startsWith(EncFSVolume.PATH_SEPARATOR) && (!name.equals(EncFSVolume.ROOT_PATH))) {
throw new IllegalArgumentException("Invalid name " + name);
}
this.name = name;
this.parentPath = parentPath;
@ -98,8 +98,7 @@ public class EncFSFileInfo {
public String getPath() {
String result;
if (parentPath.endsWith(EncFSVolume.PATH_SEPARATOR)
|| name.startsWith(EncFSVolume.PATH_SEPARATOR)) {
if (parentPath.endsWith(EncFSVolume.PATH_SEPARATOR) || name.startsWith(EncFSVolume.PATH_SEPARATOR)) {
result = parentPath + name;
} else {
result = EncFSVolume.combinePath(parentPath, name);
@ -172,9 +171,7 @@ public class EncFSFileInfo {
* @param fileInfo EncFSFileInfo for the file to be decoded
* @return EncFSFileInfo for the decoded file
*/
public static EncFSFileInfo getDecodedFileInfo(EncFSVolume volume,
String decodedParentPath, String decodedFileName,
EncFSFileInfo fileInfo) {
public static EncFSFileInfo getDecodedFileInfo(EncFSVolume volume, String decodedParentPath, String decodedFileName, EncFSFileInfo fileInfo) {
long size;
if (fileInfo.isDirectory()) {
size = 0;
@ -182,10 +179,7 @@ public class EncFSFileInfo {
size = volume.getDecryptedFileLength(fileInfo.getSize());
}
EncFSFileInfo decEncFileInfo = new EncFSFileInfo(decodedFileName,
decodedParentPath, fileInfo.isDirectory(),
fileInfo.getLastModified(), size, fileInfo.isReadable(),
return new EncFSFileInfo(decodedFileName, decodedParentPath, fileInfo.isDirectory(), fileInfo.getLastModified(), size, fileInfo.isReadable(),
fileInfo.isWritable(), fileInfo.isExecutable());
return decEncFileInfo;
}
}

View file

@ -29,20 +29,10 @@ import java.util.List;
*/
public class EncFSLocalFileProvider implements EncFSFileProvider {
/**
* Path separator for the local filesystem
*/
public final String separator;
// Root path of this file provider
private final File rootPath;
/**
* Creates a new EncFSLocalFileProvider
*
* @param rootPath Root path of the file provider (all other paths will be
* relative to this)
*/
public EncFSLocalFileProvider(File rootPath) {
this.rootPath = rootPath;
this.separator = File.separator;
@ -53,10 +43,6 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
* underlying filesystem
*
* @param srcPath Path of the source file or directory
* @return true if path represents a directory, false otherwise
* <p/>
* <p/>
* Source file/dir doesn't exist or misc. I/O error
*/
public boolean isDirectory(String srcPath) {
File file = new File(rootPath.getAbsoluteFile(), srcPath);
@ -67,11 +53,9 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
* Get a File object representing the given path
*
* @param path Path of the file or directory
* @return File object representing the given path
*/
public File getFile(String path) {
File file = new File(rootPath.getAbsoluteFile(), path);
return file;
return new File(rootPath.getAbsoluteFile(), path);
}
/**
@ -96,24 +80,15 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
* Returns whether the file or directory exists
*
* @param srcPath Path of the file or directory
* @return true if file or directory exists, false otherwise
* <p/>
* <p/>
* Misc. I/O error
*/
public boolean exists(String srcPath) {
File file = new File(rootPath.getAbsoluteFile(), srcPath);
return file.exists();
return new File(rootPath.getAbsoluteFile(), srcPath).exists();
}
/**
* Return EncFSFileInfo for the given file or directory
*
* @param srcPath Path of the file or directory
* @return EncFSFileInfo for the given file or directory
* <p/>
* <p/>
* Path doesn't exist or misc. I/O error
*/
public EncFSFileInfo getFileInfo(String srcPath) {
File sourceFile = new File(rootPath.getAbsoluteFile(), srcPath);
@ -124,10 +99,6 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
* Returns the list of files under the given directory path
*
* @param dirPath Path of the directory to list files from
* @return a List of EncFSFileInfo representing files under the dir
* <p/>
* <p/>
* Path not a directory or misc. I/O error
*/
public List<EncFSFileInfo> listFiles(String dirPath) throws IOException {
File srcDir = new File(rootPath.getAbsoluteFile(), dirPath);
@ -148,18 +119,13 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
*
* @param srcPath Path to the source file or directory
* @param dstPath Path for the destination file or directory
* @return true if the move is successful, false otherwise
* <p/>
* <p/>
* Source file/dir doesn't exist or misc. I/O error
*/
public boolean move(String srcPath, String dstPath) throws IOException {
File sourceFile = new File(rootPath.getAbsoluteFile(), srcPath);
File destFile = new File(rootPath.getAbsoluteFile(), dstPath);
if (!sourceFile.exists()) {
throw new FileNotFoundException("Path '" + srcPath
+ "' doesn't exist!");
throw new FileNotFoundException("Path '" + srcPath + "' doesn't exist!");
}
return sourceFile.renameTo(destFile);
@ -184,9 +150,6 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
*
* @param srcPath Path of the source file or directory
* @return true if deletion is successful, false otherwise
* <p/>
* <p/>
* Source file/dir doesn't exist or misc. I/O error
*/
public boolean delete(String srcPath) {
File toEncFile = new File(rootPath.getAbsoluteFile(), srcPath);
@ -207,20 +170,14 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
* method. If that is not true mkdirs should be used instead
*
* @param dirPath Path to create a directory under
* @return true if creation succeeds, false otherwise
* <p/>
* <p/>
* Path doesn't exist or misc. I/O error
*/
public boolean mkdir(String dirPath) throws IOException {
File file = new File(rootPath.getAbsoluteFile(), dirPath);
File parentFile = file.getParentFile();
if (!parentFile.exists()) {
throw new FileNotFoundException("Path '"
+ parentFile.getAbsolutePath() + "' doesn't exist!");
throw new FileNotFoundException("Path '" + parentFile.getAbsolutePath() + "' doesn't exist!");
}
boolean result = file.mkdir();
return result;
return file.mkdir();
}
/**
@ -229,15 +186,10 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
* Intermediate directories are also created by this method
*
* @param dirPath Path to create a directory under
* @return true if creation succeeds, false otherwise
* <p/>
* <p/>
* Path doesn't exist or misc. I/O error
*/
public boolean mkdirs(String dirPath) {
File toEncFile = new File(rootPath.getAbsoluteFile(), dirPath);
boolean result = toEncFile.mkdirs();
return result;
return toEncFile.mkdirs();
}
/**
@ -245,9 +197,6 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
*
* @param dstFilePath Path for the file to create
* @return EncFSFileInfo for the created file
* <p/>
* <p/>
* File already exists or misc. I/O error
*/
public EncFSFileInfo createFile(String dstFilePath) throws IOException {
if (exists(dstFilePath)) {
@ -255,7 +204,7 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
}
File targetFile = getFile(dstFilePath);
if (targetFile.createNewFile() == false) {
if (!targetFile.createNewFile()) {
throw new IOException("failed to create new file");
}
@ -267,11 +216,6 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
*
* @param srcFilePath Path to the file to copy
* @param dstFilePath Path to the destination file
* @return true if copy was successful, false otherwise
* <p/>
* <p/>
* Destination file already exists, source file doesn't exist or
* misc. I/O error
*/
public boolean copy(String srcFilePath, String dstFilePath)
throws IOException {
@ -312,9 +256,6 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
*
* @param srcFilePath Path to the source file
* @return InputStream to read from the file
* <p/>
* <p/>
* Source file doesn't exist or misc. I/O error
*/
public InputStream openInputStream(String srcFilePath)
throws FileNotFoundException {
@ -326,10 +267,6 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
* Open an OutputStream to the given file
*
* @param dstFilePath Path to the destination file
* @return OutputStream to write to the file
* <p/>
* <p/>
* Misc. I/O error
*/
public OutputStream openOutputStream(String dstFilePath) throws IOException {
return openOutputStream(dstFilePath, 0);
@ -341,15 +278,10 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
* @param dstFilePath Path to the destination file
* @param outputLength Length in bytes of the stream that will be written to this
* stream. It is ignored by this class.
* @return OutputStream to write to the file
* <p/>
* <p/>
* Misc. I/O error
*/
public OutputStream openOutputStream(String dstFilePath, long outputLength)
throws IOException {
public OutputStream openOutputStream(String dstFilePath, long outputLength) throws IOException {
File srcF = new File(rootPath.getAbsoluteFile(), dstFilePath);
if (srcF.exists() == false) {
if (!srcF.exists()) {
try {
srcF.createNewFile();
} catch (Exception e) {
@ -369,15 +301,11 @@ public class EncFSLocalFileProvider implements EncFSFileProvider {
// File is child of the root path
relativePath = separator;
} else {
relativePath = file.getParentFile().getAbsolutePath()
.substring(rootPath.getAbsoluteFile().toString().length());
relativePath = file.getParentFile().getAbsolutePath().substring(rootPath.getAbsoluteFile().toString().length());
}
String name = file.getName();
EncFSFileInfo result = new EncFSFileInfo(name, relativePath,
file.isDirectory(), file.lastModified(), file.length(),
file.canRead(), file.canWrite(), file.canExecute());
return result;
return new EncFSFileInfo(name, relativePath, file.isDirectory(), file.lastModified(), file.length(), file.canRead(), file.canWrite(), file.canExecute());
}
}

View file

@ -74,11 +74,11 @@ public final class EncFSVolumeBuilder {
this.provider = provider;
}
public PasswordBuilder withPassword(String password) throws EncFSInvalidConfigException, EncFSUnsupportedException, EncFSCorruptDataException, IOException, EncFSInvalidPasswordException {
public PasswordBuilder withPassword(String password) {
return new PasswordBuilder(volume, password, provider);
}
public PasswordBuilder withDerivedPassword(byte[] derivedPassword) throws EncFSCorruptDataException, EncFSInvalidPasswordException, EncFSInvalidConfigException, EncFSUnsupportedException, IOException {
public PasswordBuilder withDerivedPassword(byte[] derivedPassword) {
return new PasswordBuilder(volume, derivedPassword);
}
}
@ -113,7 +113,7 @@ public final class EncFSVolumeBuilder {
return volume;
}
public void create() throws EncFSUnsupportedException, IOException, EncFSInvalidConfigException, EncFSInvalidPasswordException, EncFSCorruptDataException {
public void create() throws EncFSUnsupportedException, IOException, EncFSInvalidConfigException, EncFSCorruptDataException {
EncFSConfig config = volume.getVolumeConfiguration();
EncFSFileProvider fileProvider = volume.getFileProvider();

View file

@ -8,7 +8,7 @@ public abstract class NotNullFilenameDecryptionStrategy extends FilenameDecrypti
super(volume, volumePath, algorithm);
}
protected abstract byte[] decryptConcrete(EncFSVolume volume, byte[] chainIv, byte[] macBytes, byte[] encFileName, byte[] fileIv) throws EncFSCorruptDataException;
protected abstract byte[] decryptConcrete(EncFSVolume volume, byte[] encFileName, byte[] fileIv) throws EncFSCorruptDataException;
protected String decryptImpl(String fileName) throws EncFSCorruptDataException, EncFSChecksumException {
EncFSVolume volume = getVolume();
@ -21,7 +21,7 @@ public abstract class NotNullFilenameDecryptionStrategy extends FilenameDecrypti
byte[] encFileName = Arrays.copyOfRange(base256FileName, 2, base256FileName.length);
byte[] fileIv = EncFSCrypto.computeFileIV(chainIv, macBytes);
byte[] decFileName = decryptConcrete(volume, chainIv, macBytes, encFileName, fileIv);
byte[] decFileName = decryptConcrete(volume, encFileName, fileIv);
verifyDecryptionWorked(volume, chainIv, base256FileName, decFileName);

View file

@ -10,7 +10,7 @@ public class StreamFilenameDecryptionStrategy extends NotNullFilenameDecryptionS
super(volume, volumePath, EncFSAlgorithm.STREAM);
}
protected byte[] decryptConcrete(EncFSVolume volume, byte[] chainIv, byte[] macBytes, byte[] encFileName, byte[] fileIv) throws EncFSCorruptDataException {
protected byte[] decryptConcrete(EncFSVolume volume, byte[] encFileName, byte[] fileIv) throws EncFSCorruptDataException {
try {
return StreamCryptography.streamDecode(volume, fileIv, encFileName);
} catch (InvalidAlgorithmParameterException e) {