mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 22:09:47 -04:00
Experiment with PGP signed messages
This commit is contained in:
parent
03fb5b3b94
commit
be082ab863
@ -34,9 +34,12 @@ public class License implements Serializable {
|
||||
private long id;
|
||||
private long expires;
|
||||
|
||||
public License(byte[] bytes) throws Exception {
|
||||
private Exception error;
|
||||
|
||||
public License(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
|
||||
try {
|
||||
// verify and get clear signed content
|
||||
Map<String, String> properties = getProperties();
|
||||
|
||||
@ -45,10 +48,9 @@ public class License implements Serializable {
|
||||
|
||||
// verify license online
|
||||
verifyLicense();
|
||||
} catch (Exception e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
public boolean expired() {
|
||||
return expires > System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() throws Exception {
|
||||
@ -97,6 +99,16 @@ public class License implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public void check() throws Exception {
|
||||
if (error != null) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (expires > System.currentTimeMillis()) {
|
||||
throw new IllegalStateException("Expired: " + toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s (Valid-Until: %s)", id, Instant.ofEpochMilli(expires).atZone(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
|
@ -8,7 +8,7 @@ import java.io.File;
|
||||
|
||||
import net.filebot.util.SystemProperty;
|
||||
|
||||
public enum LicenseType {
|
||||
public enum LicenseModel {
|
||||
|
||||
MicrosoftStore {
|
||||
|
||||
@ -33,16 +33,12 @@ public enum LicenseType {
|
||||
PGPSignedMessage {
|
||||
|
||||
public final SystemProperty<File> LICENSE_FILE = SystemProperty.of("net.filebot.license", File::new, ApplicationFolder.AppData.resolve("license.txt"));
|
||||
public final Resource<License> LICENSE = Resource.lazy(() -> new License(readFile(LICENSE_FILE.get())));
|
||||
public final MemoizedResource<License> LICENSE = Resource.lazy(() -> new License(readFile(LICENSE_FILE.get())));
|
||||
|
||||
@Override
|
||||
public void check() throws LicenseError {
|
||||
try {
|
||||
License license = LICENSE.get();
|
||||
|
||||
if (license.expired()) {
|
||||
throw new LicenseError("Expired: " + license);
|
||||
}
|
||||
LICENSE.get().check();
|
||||
} catch (Exception e) {
|
||||
throw new LicenseError(e.getMessage());
|
||||
}
|
||||
@ -51,7 +47,7 @@ public enum LicenseType {
|
||||
|
||||
public abstract void check() throws LicenseError;
|
||||
|
||||
public static LicenseType get() {
|
||||
public static LicenseModel get() {
|
||||
if (isUWP())
|
||||
return MicrosoftStore;
|
||||
if (isMacSandbox())
|
@ -7,7 +7,7 @@ public interface Resource<R> {
|
||||
|
||||
R get() throws Exception;
|
||||
|
||||
default Resource<R> memoize() {
|
||||
default MemoizedResource<R> memoize() {
|
||||
return new MemoizedResource<R>(this);
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ public interface Resource<R> {
|
||||
return new TransformedResource<R, T>(this, function);
|
||||
}
|
||||
|
||||
static <T> Resource<T> lazy(Resource<T> resource) {
|
||||
static <T> MemoizedResource<T> lazy(Resource<T> resource) {
|
||||
return resource.memoize();
|
||||
}
|
||||
|
||||
@ -37,6 +37,10 @@ class MemoizedResource<R> implements Resource<R> {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
|
||||
class TransformedResource<R, T> implements Resource<T> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user