Skip to content

Commit c905804

Browse files
committed
unify constants given through the spec and fix wrong constant
1 parent 4806744 commit c905804

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/main/java/org/cryptomator/cryptofs/common/Constants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ private Constants() {
2929

3030
public static final int MAX_SYMLINK_LENGTH = 32767; // max path length on NTFS and FAT32: 32k-1
3131
public static final int MAX_DIR_ID_LENGTH = 36; // UUIDv4: hex-encoded 16 byte int + 4 hyphens = 36 ASCII chars
32-
public static final int MIN_CIPHER_NAME_LENGTH = 26; //rounded up base64url encoded (16 bytes IV + 0 bytes empty string) + file suffix = 26 ASCII chars
32+
public static final int MAX_CIPHER_NAME_LENGTH = 220; // calculations done in https://github.com/cryptomator/cryptofs/issues/60#issuecomment-523238303
33+
public static final int MIN_CIPHER_NAME_LENGTH = 28; //rounded up base64url encoded (16 bytes IV + 0 bytes empty string) + file suffix = 28 ASCII chars
34+
public static final int MAX_ADDITIONAL_PATH_LENGTH = 48; // beginning at d/... see https://github.com/cryptomator/cryptofs/issues/77
3335

3436
public static final String SEPARATOR = "/";
3537
public static final String RECOVERY_DIR_NAME = "LOST+FOUND";

src/main/java/org/cryptomator/cryptofs/common/FileSystemCapabilityChecker.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
public class FileSystemCapabilityChecker {
2222

2323
private static final Logger LOG = LoggerFactory.getLogger(FileSystemCapabilityChecker.class);
24-
private static final int MAX_CIPHERTEXT_NAME_LENGTH = 220; // inclusive. calculations done in https://github.com/cryptomator/cryptofs/issues/60#issuecomment-523238303
25-
private static final int MIN_CIPHERTEXT_NAME_LENGTH = 28; // base64(iv).c9r
26-
private static final int MAX_ADDITIONAL_PATH_LENGTH = 48; // beginning at d/... see https://github.com/cryptomator/cryptofs/issues/77
2724

2825
public enum Capability {
2926
/**
@@ -95,7 +92,7 @@ public void assertWriteAccess(Path pathToVault) throws MissingCapabilityExceptio
9592

9693
public int determineSupportedCleartextFileNameLength(Path pathToVault) throws IOException {
9794
int maxCiphertextLen = determineSupportedCiphertextFileNameLength(pathToVault);
98-
assert maxCiphertextLen >= MIN_CIPHERTEXT_NAME_LENGTH;
95+
assert maxCiphertextLen >= Constants.MIN_CIPHER_NAME_LENGTH;
9996
// math explained in https://github.com/cryptomator/cryptofs/issues/60#issuecomment-523238303;
10097
// subtract 4 for file extension, base64-decode, subtract 16 for IV
10198
return (maxCiphertextLen - 4) / 4 * 3 - 16;
@@ -109,8 +106,8 @@ public int determineSupportedCleartextFileNameLength(Path pathToVault) throws IO
109106
* @throws IOException If unable to perform this check
110107
*/
111108
public int determineSupportedCiphertextFileNameLength(Path pathToVault) throws IOException {
112-
int subPathLength = MAX_ADDITIONAL_PATH_LENGTH - 2; // subtract "c/"
113-
return determineSupportedCiphertextFileNameLength(pathToVault.resolve("c"), subPathLength, MIN_CIPHERTEXT_NAME_LENGTH, MAX_CIPHERTEXT_NAME_LENGTH);
109+
int subPathLength = Constants.MAX_ADDITIONAL_PATH_LENGTH - 2; // subtract "c/"
110+
return determineSupportedCiphertextFileNameLength(pathToVault.resolve("c"), subPathLength, Constants.MIN_CIPHER_NAME_LENGTH, Constants.MAX_CIPHER_NAME_LENGTH);
114111
}
115112

116113
/**

src/test/java/org/cryptomator/cryptofs/dir/DirectoryStreamFactoryTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.cryptomator.cryptofs.CiphertextDirectory;
44
import org.cryptomator.cryptofs.CryptoPath;
55
import org.cryptomator.cryptofs.CryptoPathMapper;
6+
import org.cryptomator.cryptofs.common.Constants;
67
import org.junit.jupiter.api.Assertions;
78
import org.junit.jupiter.api.BeforeEach;
89
import org.junit.jupiter.api.DisplayName;
@@ -118,10 +119,10 @@ public void testCiphertextDirStreamFilter(String fileName, boolean expected) {
118119

119120
private static Stream<Arguments> provideFilterExamples() {
120121
return Stream.of( //
121-
Arguments.of("foo25____25chars_____.c9r", false), //
122-
Arguments.of("bar25____25chars_____.c9s", false), //
123-
Arguments.of("foo26____26chars______.c9r", true), //
124-
Arguments.of("bar26____26chars______.c9s", true));
122+
Arguments.of("b".repeat(Constants.MIN_CIPHER_NAME_LENGTH - 5)+".c9r", false), //
123+
Arguments.of("b".repeat(Constants.MIN_CIPHER_NAME_LENGTH - 5)+".c9s", false), //
124+
Arguments.of("a".repeat(Constants.MIN_CIPHER_NAME_LENGTH - 4)+".c9r", true), //
125+
Arguments.of("a".repeat(Constants.MIN_CIPHER_NAME_LENGTH - 4)+".c9s", true));
125126
}
126127

127128
}

0 commit comments

Comments
 (0)