2018-09-17 10:07:32 +03:00
|
|
|
package ru.gravit.launchserver.binary;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
2018-10-25 15:36:57 +03:00
|
|
|
import ru.gravit.launcher.serialize.signed.DigestBytesHolder;
|
2018-09-17 10:07:32 +03:00
|
|
|
import ru.gravit.launchserver.LaunchServer;
|
2018-12-06 05:29:34 +03:00
|
|
|
import ru.gravit.utils.helper.IOHelper;
|
2018-10-02 15:19:57 +03:00
|
|
|
import ru.gravit.utils.helper.SecurityHelper;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
|
|
|
public abstract class LauncherBinary {
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-12-06 05:29:34 +03:00
|
|
|
public final LaunchServer server;
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-12-06 05:29:34 +03:00
|
|
|
public final Path binaryFile;
|
|
|
|
public final Path syncBinaryFile;
|
2018-10-25 15:36:57 +03:00
|
|
|
private volatile DigestBytesHolder binary;
|
|
|
|
private volatile byte[] sign;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
protected LauncherBinary(LaunchServer server, Path binaryFile) {
|
|
|
|
this.server = server;
|
|
|
|
this.binaryFile = binaryFile;
|
|
|
|
syncBinaryFile = binaryFile;
|
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
protected LauncherBinary(LaunchServer server, Path binaryFile, Path syncBinaryFile) {
|
|
|
|
this.server = server;
|
|
|
|
this.binaryFile = binaryFile;
|
|
|
|
this.syncBinaryFile = syncBinaryFile;
|
|
|
|
}
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public abstract void build() throws IOException;
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final boolean exists() {
|
|
|
|
return IOHelper.isFile(syncBinaryFile);
|
|
|
|
}
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-10-25 15:36:57 +03:00
|
|
|
public final DigestBytesHolder getBytes() {
|
2018-09-17 10:07:32 +03:00
|
|
|
return binary;
|
|
|
|
}
|
2018-11-08 15:30:16 +03:00
|
|
|
|
2018-10-25 15:36:57 +03:00
|
|
|
public final byte[] getSign() {
|
|
|
|
return sign;
|
2018-10-02 15:19:57 +03:00
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final boolean sync() throws IOException {
|
|
|
|
boolean exists = exists();
|
2018-10-25 15:36:57 +03:00
|
|
|
binary = exists ? new DigestBytesHolder(IOHelper.read(syncBinaryFile), SecurityHelper.DigestAlgorithm.SHA512) : null;
|
2018-11-08 15:30:16 +03:00
|
|
|
sign = exists ? SecurityHelper.sign(IOHelper.read(syncBinaryFile), server.privateKey) : null;
|
2018-10-25 15:36:57 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
return exists;
|
|
|
|
}
|
|
|
|
}
|