add Paillier

This commit is contained in:
Looly
2023-06-09 22:10:55 +08:00
parent 5d26b29103
commit 04e41a6098
11 changed files with 1080 additions and 12 deletions

View File

@@ -2638,18 +2638,7 @@ public class FileUtil extends PathUtil {
*/
public static File checkSlip(final File parentFile, final File file) throws IllegalArgumentException {
if (null != parentFile && null != file) {
String parentCanonicalPath;
String canonicalPath;
try {
parentCanonicalPath = parentFile.getCanonicalPath();
canonicalPath = file.getCanonicalPath();
} catch (final IOException e) {
// issue#I4CWMO@Gitee
// getCanonicalPath有时会抛出奇怪的IO异常此时忽略异常使用AbsolutePath判断。
parentCanonicalPath = parentFile.getAbsolutePath();
canonicalPath = file.getAbsolutePath();
}
if (!canonicalPath.startsWith(parentCanonicalPath)) {
if(!file.toPath().startsWith(parentFile.toPath())){
throw new IllegalArgumentException("New file is outside of the parent dir: " + file.getName());
}
}

View File

@@ -494,4 +494,11 @@ public class FileUtilTest {
final byte[] bytes = FileUtil.readBytes("test.properties");
Assertions.assertEquals(125, bytes.length);
}
@Test
void checkSlipTest() {
Assertions.assertThrows(IllegalArgumentException.class, ()->{
FileUtil.checkSlip(FileUtil.file("test/a"), FileUtil.file("test/../a"));
});
}
}