[FIX] Удалены костыли.

This commit is contained in:
Zaxar163 2019-06-11 12:14:08 +03:00
parent d1132806da
commit 0b6f4e516b
2 changed files with 5 additions and 30 deletions

View file

@ -5,7 +5,6 @@
import pro.gravit.launcher.serialize.signed.DigestBytesHolder; import pro.gravit.launcher.serialize.signed.DigestBytesHolder;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.utils.helper.CommonHelper;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper;
@ -41,19 +40,10 @@ public void init() {
public final boolean sync() throws IOException { public final boolean sync() throws IOException {
boolean exists = exists(); boolean exists = exists();
CommonHelper.removeExc(sign);
if (binary != null) {
CommonHelper.removeExc(binary.getBytes());
CommonHelper.removeExc(binary.getDigest());
}
binary = exists ? new DigestBytesHolder(IOHelper.read(syncBinaryFile), SecurityHelper.DigestAlgorithm.SHA512) : null; binary = exists ? new DigestBytesHolder(IOHelper.read(syncBinaryFile), SecurityHelper.DigestAlgorithm.SHA512) : null;
sign = exists ? SecurityHelper.sign(IOHelper.read(syncBinaryFile), server.privateKey) : null; sign = exists ? SecurityHelper.sign(IOHelper.read(syncBinaryFile), server.privateKey) : null;
CommonHelper.addExc(sign);
if (binary != null) { return exists;
CommonHelper.addExc(binary.getBytes());
CommonHelper.addExc(binary.getDigest());
}
return exists;
} }
public static Path resolve(LaunchServer server, String ext) { public static Path resolve(LaunchServer server, String ext) {

View file

@ -5,8 +5,6 @@
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -142,23 +140,10 @@ public static GsonBuilder newBuilder() {
ByteArrayToBase64TypeAdapter.INSTANCE); ByteArrayToBase64TypeAdapter.INSTANCE);
} }
public static void addExc(byte[] exclusion) {
if (exclusion == null) return;
JsonArray add = new JsonArray(exclusion.length);
for (byte b : exclusion) add.add(new JsonPrimitive(b));
ByteArrayToBase64TypeAdapter.exclusions.put(exclusion, add);
}
public static void removeExc(byte[] exclusion) {
if (exclusion == null) return;
ByteArrayToBase64TypeAdapter.exclusions.remove(exclusion);
}
private static class ByteArrayToBase64TypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> { private static class ByteArrayToBase64TypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
private static final ByteArrayToBase64TypeAdapter INSTANCE = new ByteArrayToBase64TypeAdapter(); private static final ByteArrayToBase64TypeAdapter INSTANCE = new ByteArrayToBase64TypeAdapter();
private static final Map<byte[], JsonElement> exclusions = new ConcurrentHashMap<>(); private Base64.Decoder decoder = Base64.getUrlDecoder();
private final Base64.Decoder decoder = Base64.getUrlDecoder(); private Base64.Encoder encoder = Base64.getUrlEncoder();
private final Base64.Encoder encoder = Base64.getUrlEncoder();
public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonArray()) { if (json.isJsonArray()) {
JsonArray byteArr = json.getAsJsonArray(); JsonArray byteArr = json.getAsJsonArray();
@ -172,7 +157,7 @@ public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationCon
} }
public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) { public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) {
return exclusions.getOrDefault(src, new JsonPrimitive(encoder.encodeToString(src))); return new JsonPrimitive(encoder.encodeToString(src));
} }
} }
} }