Skip to content

Commit

Permalink
Fix a number of style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ties committed Apr 9, 2024
1 parent 5c17bea commit 4f450e9
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 32 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ next (snapshot) release, e.g. `1.1-SNAPSHOT` after releasing `1.0`.

## Changelog

## 2024-xx-yy 1.40
* Clean up some style (SonarQube) warnings

## 2024-04-08 1.39.1
* Fix: Javadoc syntax error that broke the previous release tag
* Javadoc now runs on ever `verify` build.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.ripe.ipresource.IpResourceType;
import net.ripe.rpki.commons.crypto.ValidityPeriod;
import org.apache.commons.lang3.Validate;
import org.bouncycastle.asn1.x509.PolicyInformation;

import javax.security.auth.x500.X500Principal;
import java.math.BigInteger;
Expand All @@ -29,7 +28,7 @@ public X509ResourceCertificateBuilder() {
builderHelper = new X509CertificateBuilderHelper();
builderHelper.withResources(resources);
// https://tools.ietf.org/html/rfc6487#section-4.8.9
builderHelper.withPolicies(X509ResourceCertificate.POLICY_INFORMATION);
builderHelper.withPolicies(AbstractX509CertificateWrapper.POLICY_INFORMATION);
}

public X509ResourceCertificateBuilder withSignatureProvider(String signatureProvider) {
Expand Down Expand Up @@ -111,6 +110,7 @@ public X509ResourceCertificate build() {
return new X509ResourceCertificate(builderHelper.generateCertificate());
}

@SuppressWarnings("java:S1319")
public X509ResourceCertificateBuilder withInheritedResourceTypes(EnumSet<IpResourceType> resourceTypes) {
this.inheritedResourceTypes = resourceTypes;
builderHelper.withInheritedResourceTypes(resourceTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import net.ripe.rpki.commons.crypto.x509cert.X509CertificateParser;

import java.security.cert.X509Certificate;

import static net.ripe.rpki.commons.validation.ValidationString.*;

public class ProvisioningCmsCertificateParser extends X509CertificateParser<ProvisioningCmsCertificate> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package net.ripe.rpki.commons.provisioning.x509;

import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
import net.ripe.rpki.commons.crypto.ValidityPeriod;
import net.ripe.rpki.commons.crypto.x509cert.X509CertificateBuilderHelper;
import net.ripe.rpki.commons.util.UTC;
import org.apache.commons.lang3.Validate;
import org.bouncycastle.asn1.x509.KeyUsage;
import org.joda.time.DateTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import net.ripe.rpki.commons.crypto.x509cert.X509CertificateParser;

import java.security.cert.X509Certificate;

import static net.ripe.rpki.commons.validation.ValidationString.*;

public class ProvisioningIdentityCertificateParser extends X509CertificateParser<ProvisioningIdentityCertificate> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public boolean equals(Object o) {

ValidationLocation that = (ValidationLocation) o;

if (!name.equals(that.name)) {
return false;
}

return true;
return name.equals(that.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.ripe.rpki.commons.validation;

import lombok.EqualsAndHashCode;
import net.ripe.rpki.commons.util.EqualsSupport;

import java.io.Serializable;

/**
* Captures interesting statistics related to validation.
*/
@EqualsAndHashCode
public class ValidationMetric extends EqualsSupport implements Serializable {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;

public final class ValidationResult implements Serializable {

Expand Down Expand Up @@ -195,10 +196,9 @@ public boolean rejectIfNotNull(Object object, String key, String... param) {
}

public ValidationResult addMetric(String name, String value) {
if (!metrics.containsKey(currentLocation)) {
metrics.put(currentLocation, new ArrayList<>());
}
metrics.get(currentLocation).add(new ValidationMetric(name, value, DateTimeUtils.currentTimeMillis()));
var metricsForLocation = metrics.computeIfAbsent(currentLocation, (x) -> new ArrayList<>());
metricsForLocation.add(new ValidationMetric(name, value, DateTimeUtils.currentTimeMillis()));

return this;
}

Expand Down Expand Up @@ -235,15 +235,13 @@ public boolean hasNoFailuresOrWarnings() {
}

public Set<ValidationCheck> getFailuresForCurrentLocation() {
return new HashSet<ValidationCheck>(getFailures(currentLocation));
return new HashSet<>(getFailures(currentLocation));
}

public List<ValidationCheck> getFailuresForAllLocations() {
List<ValidationCheck> failures = new ArrayList<ValidationCheck>();
for (ResultsPerLocation checks : results.values()) {
failures.addAll(checks.error);
}
return failures;
return results.values().stream()
.flatMap(location -> location.error.stream())
.collect(Collectors.toList());
}

public List<ValidationCheck> getFailures(ValidationLocation location) {
Expand All @@ -266,11 +264,9 @@ public boolean hasFailureForLocation(ValidationLocation location) {
}

public List<ValidationCheck> getWarnings() {
List<ValidationCheck> warnings = new ArrayList<ValidationCheck>();
for (ResultsPerLocation checks : results.values()) {
warnings.addAll(checks.warning);
}
return warnings;
return results.values().stream()
.flatMap(location -> location.warning.stream())
.collect(Collectors.toList());
}

public List<ValidationCheck> getAllValidationChecksForCurrentLocation() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package net.ripe.rpki.commons.validation.roa;

import lombok.Singular;
import lombok.experimental.UtilityClass;
import net.ripe.ipresource.IpRange;
import net.ripe.ipresource.IpResource;
import net.ripe.ipresource.etree.IpResourceIntervalStrategy;
import net.ripe.ipresource.etree.NestedIntervalMap;
import net.ripe.rpki.commons.crypto.cms.roa.RoaPrefix;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -76,7 +74,7 @@ private static <T extends RoaPrefixData> boolean isUnknown(T allowedRoute, IpRan
}

private static <T extends RoaPrefixData> boolean isLengthInvalid(T allowedRoute, IpRange announcedPrefix) {
return !(announcedPrefix.getPrefixLength() <= allowedRoute.getMaximumLength());
return announcedPrefix.getPrefixLength() > allowedRoute.getMaximumLength();
}

private static <T extends RoaPrefixData, U extends RouteData> boolean isAsnInvalid(T allowedRoute, U announcedRoute) {
Expand Down

1 comment on commit 4f450e9

@ties
Copy link
Member Author

@ties ties commented on 4f450e9 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not intend to push to main. Will re-enable branch protection that was disabled for releases.

Please sign in to comment.