Add Verification.fromString(string), equals(other) and hashCode()

This commit is contained in:
Paul Schaub 2022-11-07 16:21:34 +01:00
parent dad75bb522
commit 137d2e7f85
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -20,6 +20,15 @@ public class Verification {
this.signingCertFingerprint = signingCertFingerprint;
}
public static Verification fromString(String toString) {
String[] split = toString.trim().split(" ");
if (split.length != 3) {
throw new IllegalArgumentException("Verification must be of the format 'UTC-DATE OpenPGPFingerprint OpenPGPFingerprint'");
}
return new Verification(UTCUtil.parseUTCDate(split[0]), split[1], split[2]);
}
/**
* Return the signatures' creation time.
*
@ -55,4 +64,24 @@ public class Verification {
' ' +
getSigningCertFingerprint();
}
@Override
public int hashCode() {
return toString().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (!(obj instanceof Verification)) {
return false;
}
Verification other = (Verification) obj;
return toString().equals(other.toString());
}
}