Skip to content

Commit f0d0def

Browse files
committed
sonarcloud
1 parent 7d8642d commit f0d0def

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Collection;
2626
import java.util.Collections;
2727
import java.util.List;
28+
import java.util.Set;
2829

2930
/**
3031
* Builds {@link SSLSocketFactory} and {@link X509ExtendedTrustManager} instances for verifying
@@ -125,9 +126,9 @@ private static KeyStore loadKeyStore(InputStream in, char[] password)
125126
// Try JKS first since it remains the JVM default; fall back to PKCS12 which is portable
126127
// across both bcprov-jdk18on and bc-fips. We do not pin a provider; whichever provider is
127128
// registered fulfills the request.
128-
byte[] bytes = readAll(in);
129+
byte[] bytes = in.readAllBytes();
129130
KeyStoreException last = null;
130-
for (String type : new String[]{KeyStore.getDefaultType(), "JKS", "PKCS12"}) {
131+
for (String type : Set.of(KeyStore.getDefaultType(), "JKS", "PKCS12")) {
131132
try {
132133
KeyStore ks = KeyStore.getInstance(type);
133134
ks.load(new java.io.ByteArrayInputStream(bytes), password);
@@ -139,17 +140,7 @@ private static KeyStore loadKeyStore(InputStream in, char[] password)
139140
last = new KeyStoreException(e);
140141
}
141142
}
142-
throw last != null ? last : new KeyStoreException("could not load keystore");
143-
}
144-
145-
private static byte[] readAll(InputStream in) throws IOException {
146-
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
147-
byte[] buf = new byte[8192];
148-
int n;
149-
while ((n = in.read(buf)) >= 0) {
150-
out.write(buf, 0, n);
151-
}
152-
return out.toByteArray();
143+
throw last;
153144
}
154145

155146
private static X509ExtendedTrustManager extractTrustManager(KeyStore trustStore)

0 commit comments

Comments
 (0)