Skip to content

Commit bf6545c

Browse files
committed
sonar
1 parent 9abf842 commit bf6545c

File tree

4 files changed

+4
-28
lines changed

4 files changed

+4
-28
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/AddressNormalizer.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55

6-
import java.net.MalformedURLException;
76
import java.net.URI;
87
import java.net.URISyntaxException;
9-
import java.net.URL;
108

119
class AddressNormalizer {
1210
private static final Logger logger = LoggerFactory.getLogger(AddressNormalizer.class);
@@ -22,10 +20,11 @@ static String normalizeAddress(String urlString, boolean usePlaintext) {
2220
throw new SDKException("error trying to parse URL [" + urlString + "]", e);
2321
}
2422

23+
final String scheme = usePlaintext ? "http" : "https";
2524
if (uri.getHost() == null) {
2625
// if there is no host then we are likely dealing with a host and port
2726
try {
28-
uri = new URI(usePlaintext ? "http" : "https", null, uri.getScheme(), Integer.parseInt(uri.getSchemeSpecificPart()), null, null, null);
27+
uri = new URI(scheme, null, uri.getScheme(), Integer.parseInt(uri.getSchemeSpecificPart()), null, null, null);
2928
} catch (URISyntaxException e) {
3029
throw new SDKException("error trying to create URL for host and port[" + urlString + "]", e);
3130
}
@@ -36,7 +35,6 @@ static String normalizeAddress(String urlString, boolean usePlaintext) {
3635
} else {
3736
port = uri.getPort();
3837
}
39-
final String scheme = usePlaintext ? "http" : "https";
4038

4139
try {
4240
var returnUrl = new URI(scheme, null, uri.getHost(), port, null, null, null).toString();
@@ -46,19 +44,4 @@ static String normalizeAddress(String urlString, boolean usePlaintext) {
4644
throw new SDKException("error creating KAS address", e);
4745
}
4846
}
49-
50-
private static URI tryParseHostAndPort(String urlString) {
51-
URI uri;
52-
try {
53-
uri = new URI(null, urlString, null, null, null).parseServerAuthority();
54-
} catch (URISyntaxException e) {
55-
throw new SDKException("error trying to parse host and port", e);
56-
}
57-
58-
try {
59-
return new URI(uri.getPort() == 443 ? "https" : "http", null, uri.getHost(), uri.getPort(), "", "", "");
60-
} catch (URISyntaxException e) {
61-
throw new SDKException("error trying to create URL from host and port", e);
62-
}
63-
}
6447
}

sdk/src/main/java/io/opentdf/platform/sdk/NanoTDF.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.opentdf.platform.sdk;
22

33
import com.connectrpc.ResponseMessageKt;
4-
import io.opentdf.platform.policy.kasregistry.KeyAccessServerRegistryServiceClient;
54
import io.opentdf.platform.policy.kasregistry.ListKeyAccessServersRequest;
65
import io.opentdf.platform.policy.kasregistry.ListKeyAccessServersResponse;
76
import io.opentdf.platform.sdk.TDF.KasAllowlistException;

sdk/src/main/java/io/opentdf/platform/sdk/TDF.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package io.opentdf.platform.sdk;
22

33
import com.connectrpc.ConnectException;
4-
import com.connectrpc.ResponseMessageKt;
54
import com.google.gson.Gson;
65
import com.google.gson.GsonBuilder;
76
import com.nimbusds.jose.*;
87

98
import io.opentdf.platform.policy.Value;
10-
import io.opentdf.platform.policy.attributes.AttributesServiceClient;
11-
import io.opentdf.platform.policy.kasregistry.KeyAccessServerRegistryServiceClient;
129
import io.opentdf.platform.policy.kasregistry.ListKeyAccessServersRequest;
1310
import io.opentdf.platform.policy.kasregistry.ListKeyAccessServersResponse;
1411
import io.opentdf.platform.sdk.Config.TDFConfig;

sdk/src/test/java/io/opentdf/platform/sdk/TDFTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import io.opentdf.platform.sdk.TDF.Reader;
1212
import io.opentdf.platform.sdk.nanotdf.ECKeyPair;
1313
import io.opentdf.platform.sdk.nanotdf.NanoTDFType;
14-
import org.apache.commons.codec.DecoderException;
1514
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
1615
import org.junit.jupiter.api.BeforeAll;
1716
import org.junit.jupiter.api.Test;
@@ -22,12 +21,10 @@
2221
import java.io.IOException;
2322
import java.io.InputStream;
2423
import java.io.OutputStream;
25-
import java.net.URISyntaxException;
2624
import java.nio.charset.StandardCharsets;
2725
import java.security.KeyPair;
2826
import java.security.NoSuchAlgorithmException;
2927
import java.security.SecureRandom;
30-
import java.text.ParseException;
3128
import java.util.ArrayList;
3229
import java.util.Base64;
3330
import java.util.Collections;
@@ -256,7 +253,7 @@ void testSimpleTDFWithAssertionWithRS256() throws Exception {
256253
keypair.getPrivate());
257254

258255
var rsaKasInfo = new Config.KASInfo();
259-
rsaKasInfo.URL = "https://example.com/kas"+Integer.toString(0);
256+
rsaKasInfo.URL = "https://example.com/kas"+ 0;
260257

261258
Config.TDFConfig config = Config.newTDFConfig(
262259
Config.withAutoconfigure(false),
@@ -549,7 +546,7 @@ public void testCreateTDFWithMimeType() throws Exception {
549546
}
550547

551548
@Test
552-
void legacyTDFRoundTrips() throws DecoderException, IOException, JOSEException, ParseException, NoSuchAlgorithmException, URISyntaxException {
549+
void legacyTDFRoundTrips() throws IOException, NoSuchAlgorithmException {
553550
final String mimeType = "application/pdf";
554551
var assertionConfig1 = new AssertionConfig();
555552
assertionConfig1.id = "assertion1";

0 commit comments

Comments
 (0)