Skip to content

Commit 1b4550c

Browse files
committed
resolve scan issues
1 parent b0993c9 commit 1b4550c

4 files changed

Lines changed: 41 additions & 61 deletions

File tree

rlib-common/src/main/java/javasabr/rlib/common/util/FileUtils.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,19 @@
3636
import javasabr.rlib.common.util.array.ArrayComparator;
3737
import javasabr.rlib.common.util.array.ArrayFactory;
3838
import javasabr.rlib.common.util.array.UnsafeArray;
39+
import javasabr.rlib.logger.api.Logger;
3940
import javasabr.rlib.logger.api.LoggerManager;
40-
import org.jspecify.annotations.NullMarked;
4141
import org.jspecify.annotations.Nullable;
4242

4343
/**
4444
* The utility class.
4545
*
4646
* @author JavaSaBr
4747
*/
48-
@NullMarked
4948
public class FileUtils {
5049

50+
private static final Logger LOGGER = LoggerManager.getLogger(FileUtils.class);
51+
5152
public static final ArrayComparator<Path> FILE_PATH_LENGTH_COMPARATOR = (first, second) -> {
5253

5354
int firstLength = first.getNameCount();
@@ -612,7 +613,13 @@ public static void unzip(Path destination, Path zipFile) {
612613
try (var zin = new ZipInputStream(Files.newInputStream(zipFile))) {
613614
for (var entry = zin.getNextEntry(); entry != null; entry = zin.getNextEntry()) {
614615

615-
var file = destination.resolve(entry.getName());
616+
String entryName = entry.getName();
617+
if (entryName.startsWith("..")) {
618+
LOGGER.warning(entryName, "Unexpected entry name:[%s]"::formatted);
619+
continue;
620+
}
621+
622+
var file = destination.resolve(entryName);
616623

617624
if (entry.isDirectory()) {
618625
Files.createDirectories(file);

rlib-common/src/main/java/javasabr/rlib/common/util/crypt/SymmetryCrypt.java

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package javasabr.rlib.common.util.crypt;
22

3+
import java.io.Serial;
34
import java.io.UnsupportedEncodingException;
5+
import java.nio.charset.StandardCharsets;
46
import java.security.InvalidKeyException;
57
import java.security.NoSuchAlgorithmException;
68
import javax.crypto.BadPaddingException;
@@ -9,55 +11,40 @@
911
import javax.crypto.NoSuchPaddingException;
1012
import javax.crypto.SecretKey;
1113
import javax.crypto.ShortBufferException;
12-
import org.jspecify.annotations.NullMarked;
14+
import lombok.AccessLevel;
15+
import lombok.experimental.FieldDefaults;
1316

1417
/**
15-
* The symmetry crypt based on RC4.
16-
*
1718
* @author JavaSaBr
1819
*/
19-
@NullMarked
20+
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
2021
public class SymmetryCrypt {
2122

22-
/**
23-
* The crypter.
24-
*/
25-
private final Cipher ecipher;
26-
27-
/**
28-
* The encrypter.
29-
*/
30-
private final Cipher dcipher;
31-
32-
/**
33-
* THe secret key.
34-
*/
35-
private final SecretKey secretKey;
36-
37-
/**
38-
* Instantiates a new Symmetry crypt.
39-
*
40-
* @param key the key.
41-
* @throws NoSuchAlgorithmException the no such algorithm exception
42-
* @throws NoSuchPaddingException the no such padding exception
43-
* @throws UnsupportedEncodingException the unsupported encoding exception
44-
* @throws InvalidKeyException the invalid key exception
45-
*/
46-
public SymmetryCrypt(final String key)
23+
public static final String ALG_RC_4 = "RC4";
24+
25+
Cipher ecipher;
26+
Cipher dcipher;
27+
28+
public SymmetryCrypt(String key)
4729
throws NoSuchAlgorithmException, NoSuchPaddingException, UnsupportedEncodingException, InvalidKeyException {
30+
this(key, ALG_RC_4);
31+
}
4832

49-
final Cipher ecipher = Cipher.getInstance("RC4");
50-
final Cipher dcipher = Cipher.getInstance("RC4");
33+
public SymmetryCrypt(String key, String algorithm)
34+
throws NoSuchAlgorithmException, NoSuchPaddingException, UnsupportedEncodingException, InvalidKeyException {
5135

52-
final byte[] bytes = key.getBytes("UTF-8");
36+
Cipher ecipher = Cipher.getInstance(algorithm);
37+
Cipher dcipher = Cipher.getInstance(algorithm);
5338

54-
secretKey = new SecretKey() {
39+
byte[] bytes = key.getBytes(StandardCharsets.UTF_8);
40+
var secretKey = new SecretKey() {
5541

42+
@Serial
5643
private static final long serialVersionUID = -8907627571317506056L;
5744

5845
@Override
5946
public String getAlgorithm() {
60-
return "RC4";
47+
return algorithm;
6148
}
6249

6350
@Override
@@ -78,34 +65,12 @@ public String getFormat() {
7865
this.dcipher = dcipher;
7966
}
8067

81-
/**
82-
* Decrypt data.
83-
*
84-
* @param in the encrypted data.
85-
* @param offset the offset.
86-
* @param length the length.
87-
* @param out the buffer to store decrypted data.
88-
* @throws ShortBufferException the short buffer exception
89-
* @throws IllegalBlockSizeException the illegal block size exception
90-
* @throws BadPaddingException the bad padding exception
91-
*/
92-
public void decrypt(final byte[] in, final int offset, final int length, final byte[] out)
68+
public void decrypt(byte[] in, int offset, int length, byte[] out)
9369
throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
9470
dcipher.doFinal(in, offset, length, out, offset);
9571
}
9672

97-
/**
98-
* Encrypt data.
99-
*
100-
* @param in the decrypted data.
101-
* @param offset the offset.
102-
* @param length the length.
103-
* @param out the buffer to store encrypted data.
104-
* @throws ShortBufferException the short buffer exception
105-
* @throws IllegalBlockSizeException the illegal block size exception
106-
* @throws BadPaddingException the bad padding exception
107-
*/
108-
public void encrypt(final byte[] in, final int offset, final int length, final byte[] out)
73+
public void encrypt(byte[] in, int offset, int length, byte[] out)
10974
throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
11075
ecipher.doFinal(in, offset, length, out, offset);
11176
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package javasabr.rlib.common.util.crypt;
3+
4+
import org.jspecify.annotations.NullMarked;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@NullMarked
2+
package javasabr.rlib.common.util;
3+
4+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)