Rename EncFSAlgorithm -> EncFSFilenameEncryptionAlgorithm
This commit is contained in:
parent
dc1303866e
commit
d3f11ff3a0
20 changed files with 61 additions and 40 deletions
src
main/java/org/mrpdaemon/sec/encfs
BasicFilenameDecryptionStrategy.javaBasicFilenameEncryptionStrategy.javaBlockFilenameDecryptionStrategy.javaBlockFilenameEncryptionStrategy.javaEncFSConfig.javaEncFSConfigFactory.javaEncFSConfigParser.javaEncFSConfigWriter.javaEncFSCrypto.javaEncFSFilenameEncryptionAlgorithm.javaFilenameDecryptionStrategy.javaFilenameEncryptionStrategy.javaNullFilenameDecryptionStrategy.javaNullFilenameEncryptionStrategy.javaStreamCrypto.javaStreamFilenameDecryptionStrategy.javaStreamFilenameEncryptionStrategy.java
test/java/org/mrpdaemon/sec/encfs
|
@ -20,7 +20,7 @@ public abstract class BasicFilenameDecryptionStrategy extends
|
|||
FilenameDecryptionStrategy {
|
||||
|
||||
BasicFilenameDecryptionStrategy(EncFSVolume volume, String volumePath,
|
||||
EncFSAlgorithm algorithm) {
|
||||
EncFSFilenameEncryptionAlgorithm algorithm) {
|
||||
super(volume, volumePath, algorithm);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ public abstract class BasicFilenameEncryptionStrategy extends
|
|||
FilenameEncryptionStrategy {
|
||||
|
||||
BasicFilenameEncryptionStrategy(EncFSVolume volume, String volumePath,
|
||||
EncFSAlgorithm algorithm) {
|
||||
EncFSFilenameEncryptionAlgorithm algorithm) {
|
||||
super(volume, volumePath, algorithm);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class BlockFilenameDecryptionStrategy extends
|
|||
BasicFilenameDecryptionStrategy {
|
||||
|
||||
public BlockFilenameDecryptionStrategy(EncFSVolume volume, String volumePath) {
|
||||
super(volume, volumePath, EncFSAlgorithm.BLOCK);
|
||||
super(volume, volumePath, EncFSFilenameEncryptionAlgorithm.BLOCK);
|
||||
}
|
||||
|
||||
protected byte[] decryptConcrete(EncFSVolume volume, byte[] encFileName,
|
||||
|
|
|
@ -23,7 +23,7 @@ public class BlockFilenameEncryptionStrategy extends
|
|||
BasicFilenameEncryptionStrategy {
|
||||
|
||||
public BlockFilenameEncryptionStrategy(EncFSVolume volume, String volumePath) {
|
||||
super(volume, volumePath, EncFSAlgorithm.BLOCK);
|
||||
super(volume, volumePath, EncFSFilenameEncryptionAlgorithm.BLOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -43,7 +43,7 @@ public class EncFSConfig {
|
|||
*/
|
||||
private String base64Salt;
|
||||
private int iterationForPasswordKeyDerivationCount;
|
||||
private EncFSAlgorithm algorithm;
|
||||
private EncFSFilenameEncryptionAlgorithm algorithm;
|
||||
private int numberOfMACBytesForEachFileBlock;
|
||||
private int numberOfRandomBytesInEachMACHeader;
|
||||
private boolean supportedExternalIVChaining;
|
||||
|
@ -133,11 +133,11 @@ public class EncFSConfig {
|
|||
this.iterationForPasswordKeyDerivationCount = iterationForPasswordKeyDerivationCount;
|
||||
}
|
||||
|
||||
public EncFSAlgorithm getAlgorithm() {
|
||||
public EncFSFilenameEncryptionAlgorithm getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
public void setAlgorithm(EncFSAlgorithm algorithm) {
|
||||
public void setAlgorithm(EncFSFilenameEncryptionAlgorithm algorithm) {
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public final class EncFSConfigFactory {
|
|||
|
||||
public static EncFSConfig createDefault() {
|
||||
EncFSConfig config = new EncFSConfig();
|
||||
config.setAlgorithm(EncFSAlgorithm.BLOCK);
|
||||
config.setAlgorithm(EncFSFilenameEncryptionAlgorithm.BLOCK);
|
||||
config.setVolumeKeySizeInBits(192);
|
||||
config.setEncryptedFileBlockSizeInBytes(1024);
|
||||
config.setUseUniqueIV(true);
|
||||
|
|
|
@ -144,7 +144,7 @@ class EncFSConfigParser {
|
|||
if (nameAlgChildNode.getNodeName().equals("name")) {
|
||||
String algName = getNodeValue(nameAlgChildNode);
|
||||
try {
|
||||
config.setAlgorithm(EncFSAlgorithm
|
||||
config.setAlgorithm(EncFSFilenameEncryptionAlgorithm
|
||||
.parse(algName));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new EncFSInvalidConfigException(
|
||||
|
|
|
@ -77,7 +77,7 @@ class EncFSConfigWriter {
|
|||
|
||||
result += "\t<nameAlg>\n";
|
||||
|
||||
EncFSAlgorithm algorithm = config.getAlgorithm();
|
||||
EncFSFilenameEncryptionAlgorithm algorithm = config.getAlgorithm();
|
||||
result += "\t\t<name>" + algorithm.getIdentifier() + "</name>\n";
|
||||
result += "\t\t<major>" + algorithm.getMajor() + "</major>\n";
|
||||
result += "\t\t<minor>" + algorithm.getMinor() + "</minor>\n";
|
||||
|
|
|
@ -175,7 +175,7 @@ public class EncFSCrypto {
|
|||
String volumePath) throws EncFSCorruptDataException,
|
||||
EncFSChecksumException {
|
||||
|
||||
EncFSAlgorithm algorithm = volume.getConfig()
|
||||
EncFSFilenameEncryptionAlgorithm algorithm = volume.getConfig()
|
||||
.getAlgorithm();
|
||||
switch (algorithm) {
|
||||
case NULL:
|
||||
|
@ -195,7 +195,7 @@ public class EncFSCrypto {
|
|||
public static String encodeName(EncFSVolume volume, String fileName,
|
||||
String volumePath) throws EncFSCorruptDataException {
|
||||
|
||||
EncFSAlgorithm algorithm = volume.getConfig()
|
||||
EncFSFilenameEncryptionAlgorithm algorithm = volume.getConfig()
|
||||
.getAlgorithm();
|
||||
switch (algorithm) {
|
||||
case NULL:
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
package org.mrpdaemon.sec.encfs;
|
||||
|
||||
/**
|
||||
* User: lars
|
||||
* Enum representing the filename encryption algorithms used in EncFS
|
||||
*/
|
||||
public enum EncFSAlgorithm {
|
||||
public enum EncFSFilenameEncryptionAlgorithm {
|
||||
BLOCK("nameio/block", 3, 0), STREAM("nameio/stream", 2, 1), NULL(
|
||||
"nameio/null", 1, 0);
|
||||
|
||||
|
@ -25,14 +25,22 @@ public enum EncFSAlgorithm {
|
|||
private final int major;
|
||||
private final int minor;
|
||||
|
||||
EncFSAlgorithm(String identifier, int major, int minor) {
|
||||
EncFSFilenameEncryptionAlgorithm(String identifier, int major, int minor) {
|
||||
this.identifier = identifier;
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
public static EncFSAlgorithm parse(String identifier) {
|
||||
for (EncFSAlgorithm a : values()) {
|
||||
/**
|
||||
* Parse the given string and return the corresponding algorithm value
|
||||
*
|
||||
* @param identifier
|
||||
* String to parse
|
||||
*
|
||||
* @return EncFSFileNameEncryptionAlgorithm corresponding to the string.
|
||||
*/
|
||||
public static EncFSFilenameEncryptionAlgorithm parse(String identifier) {
|
||||
for (EncFSFilenameEncryptionAlgorithm a : values()) {
|
||||
if (a.identifier.equals(identifier)) {
|
||||
return a;
|
||||
}
|
|
@ -7,7 +7,7 @@ abstract class FilenameDecryptionStrategy {
|
|||
|
||||
private final EncFSVolume volume;
|
||||
private final String volumePath;
|
||||
private final EncFSAlgorithm algorithm;
|
||||
private final EncFSFilenameEncryptionAlgorithm algorithm;
|
||||
|
||||
String getVolumePath() {
|
||||
return volumePath;
|
||||
|
@ -18,7 +18,7 @@ abstract class FilenameDecryptionStrategy {
|
|||
}
|
||||
|
||||
FilenameDecryptionStrategy(EncFSVolume volume, String volumePath,
|
||||
EncFSAlgorithm algorithm) {
|
||||
EncFSFilenameEncryptionAlgorithm algorithm) {
|
||||
this.volume = volume;
|
||||
this.volumePath = volumePath;
|
||||
this.algorithm = algorithm;
|
||||
|
|
|
@ -7,7 +7,7 @@ abstract class FilenameEncryptionStrategy {
|
|||
|
||||
private final EncFSVolume volume;
|
||||
private final String volumePath;
|
||||
private final EncFSAlgorithm algorithm;
|
||||
private final EncFSFilenameEncryptionAlgorithm algorithm;
|
||||
|
||||
String getVolumePath() {
|
||||
return volumePath;
|
||||
|
@ -18,7 +18,7 @@ abstract class FilenameEncryptionStrategy {
|
|||
}
|
||||
|
||||
FilenameEncryptionStrategy(EncFSVolume volume, String volumePath,
|
||||
EncFSAlgorithm algorithm) {
|
||||
EncFSFilenameEncryptionAlgorithm algorithm) {
|
||||
this.volume = volume;
|
||||
this.volumePath = volumePath;
|
||||
this.algorithm = algorithm;
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.mrpdaemon.sec.encfs;
|
|||
public class NullFilenameDecryptionStrategy extends FilenameDecryptionStrategy {
|
||||
|
||||
public NullFilenameDecryptionStrategy(EncFSVolume volume, String volumePath) {
|
||||
super(volume, volumePath, EncFSAlgorithm.NULL);
|
||||
super(volume, volumePath, EncFSFilenameEncryptionAlgorithm.NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.mrpdaemon.sec.encfs;
|
|||
public class NullFilenameEncryptionStrategy extends FilenameEncryptionStrategy {
|
||||
|
||||
public NullFilenameEncryptionStrategy(EncFSVolume volume, String volumePath) {
|
||||
super(volume, volumePath, EncFSAlgorithm.NULL);
|
||||
super(volume, volumePath, EncFSFilenameEncryptionAlgorithm.NULL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -137,7 +137,7 @@ public class StreamCrypto {
|
|||
if ((curPath.length() > 0)
|
||||
&& (!curPath.equals(EncFSVolume.PATH_SEPARATOR))) {
|
||||
byte[] encodeBytes;
|
||||
if (volume.getConfig().getAlgorithm() == EncFSAlgorithm.BLOCK) {
|
||||
if (volume.getConfig().getAlgorithm() == EncFSFilenameEncryptionAlgorithm.BLOCK) {
|
||||
encodeBytes = EncFSCrypto
|
||||
.getBytesForBlockAlgorithm(curPath);
|
||||
} else {
|
||||
|
|
|
@ -9,7 +9,7 @@ public class StreamFilenameDecryptionStrategy extends
|
|||
|
||||
public StreamFilenameDecryptionStrategy(EncFSVolume volume,
|
||||
String volumePath) {
|
||||
super(volume, volumePath, EncFSAlgorithm.STREAM);
|
||||
super(volume, volumePath, EncFSFilenameEncryptionAlgorithm.STREAM);
|
||||
}
|
||||
|
||||
protected byte[] decryptConcrete(EncFSVolume volume, byte[] encFileName,
|
||||
|
|
|
@ -9,7 +9,7 @@ public class StreamFilenameEncryptionStrategy extends
|
|||
|
||||
public StreamFilenameEncryptionStrategy(EncFSVolume volume,
|
||||
String volumePath) {
|
||||
super(volume, volumePath, EncFSAlgorithm.STREAM);
|
||||
super(volume, volumePath, EncFSFilenameEncryptionAlgorithm.STREAM);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package org.mrpdaemon.sec.encfs;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* User: lars
|
||||
*/
|
||||
public class EncFSAlgorithmTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testParse() throws Exception {
|
||||
EncFSAlgorithm.parse("nameio/sstream");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* EncFS Java Library
|
||||
* Copyright (C) 2013 encfs-java authors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
package org.mrpdaemon.sec.encfs.tests;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mrpdaemon.sec.encfs.EncFSFilenameEncryptionAlgorithm;
|
||||
|
||||
public class EncFSFilenameEncryptionAlgorithmTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testParse() throws Exception {
|
||||
EncFSFilenameEncryptionAlgorithm.parse("nameio/sstream");
|
||||
}
|
||||
}
|
|
@ -107,7 +107,7 @@ public abstract class EncFSVolumeTest {
|
|||
@Test
|
||||
public void testStreamNameAlg() throws Exception {
|
||||
EncFSConfig config = EncFSConfigFactory.createDefault();
|
||||
config.setAlgorithm(EncFSAlgorithm.STREAM);
|
||||
config.setAlgorithm(EncFSFilenameEncryptionAlgorithm.STREAM);
|
||||
|
||||
testFileOperations(config);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue