1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-25 12:27:58 +01:00

Remove unnecessary fields from WebOfTrust class

This commit is contained in:
Paul Schaub 2023-06-25 20:17:28 +02:00
parent b98707320d
commit e065d99bec
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -89,8 +89,9 @@ public class WebOfTrust implements CertificateAuthority {
Optional<ReferenceTime> optReferenceTime) { Optional<ReferenceTime> optReferenceTime) {
ReferenceTime referenceTime = optReferenceTime.isPresent() ? optReferenceTime.get() : ReferenceTime.now(); ReferenceTime referenceTime = optReferenceTime.isPresent() ? optReferenceTime.get() : ReferenceTime.now();
Iterable<KeyRingInfo> validCerts = parseValidCertificates(certificates, policy, referenceTime.getTimestamp()); List<KeyRingInfo> validCerts = parseValidCertificates(certificates, policy, referenceTime.getTimestamp());
LOGGER.debug("Successfully parsed " + validCerts.size() + " certificates.");
return fromValidCertificates( return fromValidCertificates(
validCerts, validCerts,
policy, policy,
@ -98,7 +99,7 @@ public class WebOfTrust implements CertificateAuthority {
); );
} }
private static Iterable<KeyRingInfo> parseValidCertificates(Iterable<Certificate> certificates, Policy policy, Date referenceTime) { private static List<KeyRingInfo> parseValidCertificates(Iterable<Certificate> certificates, Policy policy, Date referenceTime) {
// Parse all certificates // Parse all certificates
List<KeyRingInfo> validCerts = new ArrayList<>(); List<KeyRingInfo> validCerts = new ArrayList<>();
for (Certificate cert : certificates) { for (Certificate cert : certificates) {
@ -132,7 +133,7 @@ public class WebOfTrust implements CertificateAuthority {
* @return network * @return network
*/ */
public static Network fromValidCertificates( public static Network fromValidCertificates(
Iterable<KeyRingInfo> validatedCertificates, List<KeyRingInfo> validatedCertificates,
Policy policy, Policy policy,
ReferenceTime referenceTime) { ReferenceTime referenceTime) {
@ -141,34 +142,38 @@ public class WebOfTrust implements CertificateAuthority {
return nb.buildNetwork(); return nb.buildNetwork();
} }
/**
* Class for building the {@link Network Flow network} from the given set of OpenPGP keys.
*
*/
private static final class NetworkBuilder { private static final class NetworkBuilder {
// Index structures // certificates keyed by fingerprint
private final Map<OpenPgpFingerprint, KeyRingInfo> byFingerprint = new HashMap<>(); private final Map<OpenPgpFingerprint, KeyRingInfo> byFingerprint = new HashMap<>();
// certificates keyed by (sub-) key-id
private final Map<Long, List<KeyRingInfo>> byKeyId = new HashMap<>(); private final Map<Long, List<KeyRingInfo>> byKeyId = new HashMap<>();
// certificate synopses keyed by fingerprint
private final Map<OpenPgpFingerprint, CertSynopsis> certSynopsisMap = new HashMap<>(); private final Map<OpenPgpFingerprint, CertSynopsis> certSynopsisMap = new HashMap<>();
// Issuer -> Target, Signatures by an issuer // Issuer -> Target, edges keyed by issuer
private final Map<OpenPgpFingerprint, List<CertificationSet>> edges = new HashMap<>(); private final Map<OpenPgpFingerprint, List<CertificationSet>> edges = new HashMap<>();
// Target -> Issuer, Signatures on the target // Target -> Issuer, edges keyed by target
private final Map<OpenPgpFingerprint, List<CertificationSet>> reverseEdges = new HashMap<>(); private final Map<OpenPgpFingerprint, List<CertificationSet>> reverseEdges = new HashMap<>();
private final Iterable<KeyRingInfo> validatedCertificates;
private final Policy policy; private final Policy policy;
private final ReferenceTime referenceTime; private final ReferenceTime referenceTime;
private NetworkBuilder(Iterable<KeyRingInfo> validatedCertificates, private NetworkBuilder(List<KeyRingInfo> validatedCertificates,
Policy policy, Policy policy,
ReferenceTime referenceTime) { ReferenceTime referenceTime) {
this.validatedCertificates = validatedCertificates;
this.policy = policy; this.policy = policy;
this.referenceTime = referenceTime; this.referenceTime = referenceTime;
synopsizeCertificates(); synopsizeCertificates(validatedCertificates);
findEdges(); findEdges(validatedCertificates);
} }
private void synopsizeCertificates() { private void synopsizeCertificates(List<KeyRingInfo> validatedCertificates) {
for (KeyRingInfo cert : validatedCertificates) { for (KeyRingInfo cert : validatedCertificates) {
synopsize(cert); synopsize(cert);
} }
@ -209,7 +214,7 @@ public class WebOfTrust implements CertificateAuthority {
} }
private void findEdges() { private void findEdges(List<KeyRingInfo> validatedCertificates) {
// Identify certifications and delegations // Identify certifications and delegations
// Target = cert carrying a signature // Target = cert carrying a signature
for (KeyRingInfo validatedTarget : validatedCertificates) { for (KeyRingInfo validatedTarget : validatedCertificates) {