From 9b1f715f791ec2001a783d19d0c5651db748e36c Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 28 Jun 2023 13:40:03 +0200 Subject: [PATCH] Rewrite CertSynopsis in Kotlin --- .../wot/dijkstra/sq/CertSynopsis.java | 80 ------------------- .../wot/dijkstra/sq/Certification.java | 4 +- .../wot/dijkstra/sq/CertSynopsis.kt | 20 +++++ 3 files changed, 22 insertions(+), 82 deletions(-) delete mode 100644 wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/CertSynopsis.java create mode 100644 wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/CertSynopsis.kt diff --git a/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/CertSynopsis.java b/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/CertSynopsis.java deleted file mode 100644 index 7be04c1a..00000000 --- a/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/CertSynopsis.java +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Paul Schaub -// -// SPDX-License-Identifier: Apache-2.0 - -package org.pgpainless.wot.dijkstra.sq; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.pgpainless.algorithm.RevocationState; -import org.pgpainless.key.OpenPgpFingerprint; - -public class CertSynopsis { - - private final OpenPgpFingerprint fingerprint; - private final Date expirationTime; - private final RevocationState revocationState; - private final Map userIds; - - /** - * Create a new {@link CertSynopsis}. - * - * @param fingerprint fingerprint of the certificate - * @param expirationTime expiration time - * @param revocationState revocation state of the certificate - * @param userIds set of user-ids - */ - public CertSynopsis(OpenPgpFingerprint fingerprint, - Date expirationTime, - RevocationState revocationState, - Map userIds) { - this.fingerprint = fingerprint; - this.expirationTime = expirationTime; - this.revocationState = revocationState; - this.userIds = userIds; - } - - /** - * Return the fingerprint of the certificate. - * - * @return fingerprint - */ - public OpenPgpFingerprint getFingerprint() { - return fingerprint; - } - - /** - * Get the certificates expiration time. - * - * @return expiration time - */ - public Date getExpirationTime() { - return expirationTime; - } - - /** - * Get the revocation status of the certificate. - * - * @return revocation state - */ - public RevocationState getRevocationState() { - return revocationState; - } - - /** - * Get a {@link Set} containing all user-ids of the certificate. - * - * @return user-ids - */ - public Map userIds() { - return new HashMap<>(userIds); - } - - @Override - public String toString() { - return fingerprint + (userIds.isEmpty() ? "" : "(" + userIds.keySet().iterator().next() + ")"); - } -} diff --git a/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/Certification.java b/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/Certification.java index 6a9b93d1..6cf97b58 100644 --- a/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/Certification.java +++ b/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/Certification.java @@ -140,9 +140,9 @@ public class Certification { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(issuer.getFingerprint()).append((issuer.userIds().isEmpty() ? " " : " (" + issuer.userIds().keySet().iterator().next() + ") ")); + sb.append(issuer.getFingerprint()).append((issuer.getUserIds().isEmpty() ? " " : " (" + issuer.getUserIds().keySet().iterator().next() + ") ")); sb.append(userId.isPresent() ? "certifies" : "delegates to").append(userId.isPresent() ? " [" + userId.get() + "] " : " ").append(target.getFingerprint()) - .append(userId.isEmpty() && !target.userIds().isEmpty() ? " (" + target.userIds().keySet().iterator().next() + ")" : ""); + .append(userId.isEmpty() && !target.getUserIds().isEmpty() ? " (" + target.getUserIds().keySet().iterator().next() + ")" : ""); return sb.toString(); } } diff --git a/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/CertSynopsis.kt b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/CertSynopsis.kt new file mode 100644 index 00000000..9af72037 --- /dev/null +++ b/wot-dijkstra/src/main/kotlin/org/pgpainless/wot/dijkstra/sq/CertSynopsis.kt @@ -0,0 +1,20 @@ +package org.pgpainless.wot.dijkstra.sq + +import org.pgpainless.algorithm.RevocationState +import org.pgpainless.key.OpenPgpFingerprint +import java.util.* + +data class CertSynopsis( + val fingerprint: OpenPgpFingerprint, + val expirationTime: Date?, + val revocationState: RevocationState, + val userIds : Map) { + + override fun toString(): String { + return if (userIds.isEmpty()) { + "$fingerprint" + } else { + "$fingerprint (${userIds.keys.first()})" + } + } +} \ No newline at end of file