mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 10:47:33 +02:00
Use Lombok to create a record-like struct
This commit is contained in:
@ -241,7 +241,7 @@ public class ProtocolLibListener extends PacketAdapter {
|
|||||||
Instant expires = profileKey.getExpireTime();
|
Instant expires = profileKey.getExpireTime();
|
||||||
PublicKey key = profileKey.getKey();
|
PublicKey key = profileKey.getKey();
|
||||||
byte[] signature = profileKey.getSignature();
|
byte[] signature = profileKey.getSignature();
|
||||||
ClientPublicKey clientKey = new ClientPublicKey(expires, key, signature);
|
ClientPublicKey clientKey = ClientPublicKey.of(expires, key, signature);
|
||||||
try {
|
try {
|
||||||
if (EncryptionUtil.verifyClientKey(clientKey, Instant.now())) {
|
if (EncryptionUtil.verifyClientKey(clientKey, Instant.now())) {
|
||||||
return Optional.of(clientKey);
|
return Optional.of(clientKey);
|
||||||
|
@ -27,62 +27,16 @@ package com.github.games647.fastlogin.bukkit.listener.protocollib.packet;
|
|||||||
|
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
|
|
||||||
public final class ClientPublicKey {
|
import lombok.Value;
|
||||||
private final Instant expiry;
|
import lombok.experimental.Accessors;
|
||||||
private final PublicKey key;
|
|
||||||
private final byte[] signature;
|
|
||||||
|
|
||||||
public ClientPublicKey(Instant expiry, PublicKey key, byte[] signature) {
|
@Accessors(fluent = true)
|
||||||
this.expiry = expiry;
|
@Value(staticConstructor = "of")
|
||||||
this.key = key;
|
public class ClientPublicKey {
|
||||||
this.signature = signature;
|
Instant expiry;
|
||||||
}
|
PublicKey key;
|
||||||
|
byte[] signature;
|
||||||
public Instant expiry() {
|
|
||||||
return expiry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PublicKey key() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] signature() {
|
|
||||||
return signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == this) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj == null || obj.getClass() != this.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientPublicKey that = (ClientPublicKey) obj;
|
|
||||||
return Objects.equals(this.expiry, that.expiry)
|
|
||||||
&& Objects.equals(this.key, that.key)
|
|
||||||
&& Arrays.equals(this.signature, that.signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(expiry, key, signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return new StringJoiner(", ", ClientPublicKey.class.getSimpleName() + "[", "]")
|
|
||||||
.add("expiry=" + expiry)
|
|
||||||
.add("key=" + key)
|
|
||||||
.add("signature=" + Arrays.toString(signature))
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExpired(Instant verifyTimestamp) {
|
public boolean isExpired(Instant verifyTimestamp) {
|
||||||
return !verifyTimestamp.isBefore(expiry);
|
return !verifyTimestamp.isBefore(expiry);
|
||||||
|
@ -77,7 +77,7 @@ public class ResourceLoader {
|
|||||||
RSAPublicKey publicKey = parsePublicKey(key);
|
RSAPublicKey publicKey = parsePublicKey(key);
|
||||||
|
|
||||||
byte[] signature = Base64.getDecoder().decode(object.getAsJsonPrimitive("signature").getAsString());
|
byte[] signature = Base64.getDecoder().decode(object.getAsJsonPrimitive("signature").getAsString());
|
||||||
return new ClientPublicKey(expires, publicKey, signature);
|
return ClientPublicKey.of(expires, publicKey, signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RSAPublicKey parsePublicKey(String keySpec)
|
private static RSAPublicKey parsePublicKey(String keySpec)
|
||||||
|
Reference in New Issue
Block a user