Skip to content

Commit 8e72527

Browse files
committed
resolve TODO
1 parent eb78338 commit 8e72527

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/java/org/cryptomator/cryptofs/FileNameDecryptor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ boolean hasCipherNodeExtension(Path p) {
8282
return name != null && Stream.of(Constants.CRYPTOMATOR_FILE_SUFFIX, Constants.DEFLATED_FILE_SUFFIX).anyMatch(name.toString()::endsWith);
8383
}
8484

85-
boolean isAtCipherNodeLevel(Path p) {
86-
return vaultPath.relativize(p).getNameCount() == 4; //TODO: relativize is defined for two relative Paths. For two absolute paths, the result depends on the OS
85+
boolean isAtCipherNodeLevel(Path absolutPah) {
86+
if (!absolutPah.isAbsolute()) {
87+
throw new IllegalArgumentException("Path " + absolutPah + "must be absolute");
88+
}
89+
return absolutPah.subpath(vaultPath.getNameCount(), absolutPah.getNameCount()).getNameCount() == 4;
8790
}
8891

8992
boolean hasMinimumFileNameLength(Path p) {

src/test/java/org/cryptomator/cryptofs/FileNameDecryptorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,10 @@ public void validateTooShort() {
167167
}
168168
}
169169

170+
@Test
171+
public void testIsAtCipherNodeLevelRequiresAbsolutePath() {
172+
Assertions.assertThrows(IllegalArgumentException.class, () -> testObj.isAtCipherNodeLevel(Path.of("relative/path")));
173+
}
174+
170175

171176
}

0 commit comments

Comments
 (0)