From 137d2e7f85063b24fc86041507f654ad73f6396b Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 7 Nov 2022 16:21:34 +0100 Subject: [PATCH] Add Verification.fromString(string), equals(other) and hashCode() --- sop-java/src/main/java/sop/Verification.java | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sop-java/src/main/java/sop/Verification.java b/sop-java/src/main/java/sop/Verification.java index 2047c3d..6ff63f6 100644 --- a/sop-java/src/main/java/sop/Verification.java +++ b/sop-java/src/main/java/sop/Verification.java @@ -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()); + } }