From 7dd672f06c14090189813f71b93fb692e7122f0e Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 24 Jun 2023 10:15:30 +0200 Subject: [PATCH] Add toString() methods to WOT network classes --- .../src/main/java/org/pgpainless/wot/WebOfTrust.java | 5 +++++ .../org/pgpainless/wot/dijkstra/sq/CertSynopsis.java | 5 +++++ .../org/pgpainless/wot/dijkstra/sq/Certification.java | 9 +++++++++ .../pgpainless/wot/dijkstra/sq/CertificationSet.java | 11 +++++++++++ .../java/org/pgpainless/wot/dijkstra/sq/Network.java | 11 ++++++++++- 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/pgpainless-wot/src/main/java/org/pgpainless/wot/WebOfTrust.java b/pgpainless-wot/src/main/java/org/pgpainless/wot/WebOfTrust.java index e8b7740f..98cef611 100644 --- a/pgpainless-wot/src/main/java/org/pgpainless/wot/WebOfTrust.java +++ b/pgpainless-wot/src/main/java/org/pgpainless/wot/WebOfTrust.java @@ -157,4 +157,9 @@ public class WebOfTrust implements CertificateAuthority { public boolean isAuthorized(PGPPublicKeyRing certificate, String userId) { return false; } + + @Override + public String toString() { + return network.toString(); + } } 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 index 43d3ef18..37efda07 100644 --- 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 @@ -71,4 +71,9 @@ public class CertSynopsis { public Set userIds() { return new HashSet<>(userIds); } + + @Override + public String toString() { + return fingerprint + (userIds.isEmpty() ? "" : "(" + userIds.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 23e1e36a..29d3b973 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 @@ -166,4 +166,13 @@ public class Certification { public RegexSet getRegexes() { return regex; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(issuer.getFingerprint()).append((issuer.userIds().isEmpty() ? " " : " (" + issuer.userIds().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().iterator().next() + ")" : ""); + return sb.toString(); + } } diff --git a/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/CertificationSet.java b/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/CertificationSet.java index 5a073cc1..84b1899c 100644 --- a/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/CertificationSet.java +++ b/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/CertificationSet.java @@ -110,4 +110,15 @@ public final class CertificationSet { // TODO: Prevent duplicates, only keep newest timestamped sig? certificationsForUserId.add(certification); } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Map.Entry, List> entry : certifications.entrySet()) { + for (Certification certification : entry.getValue()) { + sb.append(certification).append("\n"); + } + } + return sb.toString(); + } } diff --git a/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/Network.java b/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/Network.java index 8f4392d6..a1cfa2dd 100644 --- a/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/Network.java +++ b/wot-dijkstra/src/main/java/org/pgpainless/wot/dijkstra/sq/Network.java @@ -58,4 +58,13 @@ public class Network { return referenceTime; } -} + public String toString() { + StringBuilder sb = new StringBuilder("Network with " + getNodes().size() + " nodes, " + getEdges().size() + " edges:\n"); + for (OpenPgpFingerprint issuer : getNodes().keySet()) { + for (CertificationSet edge : getReverseEdges().get(issuer)) { + sb.append(edge); + } + } + return sb.toString(); + } +} \ No newline at end of file