Skip to content

Commit

Permalink
8289659: Refactor I/O stream copying to use InputStream.readAllBytes …
Browse files Browse the repository at this point in the history
…in X509CertPath

Reviewed-by: attila, weijun
  • Loading branch information
Andrey Turbanov committed Jul 25, 2022
1 parent 1e270ea commit 0ca74f5
Showing 1 changed file with 3 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,7 +26,6 @@
package sun.security.provider.certpath;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.CertificateEncodingException;
Expand Down Expand Up @@ -185,7 +184,7 @@ private static List<X509Certificate> parsePKIPATH(InputStream is)
}

try {
DerInputStream dis = new DerInputStream(readAllBytes(is));
DerInputStream dis = new DerInputStream(is.readAllBytes());
DerValue[] seq = dis.getSequence(3);
if (seq.length == 0) {
return Collections.<X509Certificate>emptyList();
Expand Down Expand Up @@ -228,7 +227,7 @@ private static List<X509Certificate> parsePKCS7(InputStream is)
if (is.markSupported() == false) {
// Copy the entire input stream into an InputStream that does
// support mark
is = new ByteArrayInputStream(readAllBytes(is));
is = new ByteArrayInputStream(is.readAllBytes());
}
PKCS7 pkcs7 = new PKCS7(is);

Expand All @@ -251,22 +250,6 @@ private static List<X509Certificate> parsePKCS7(InputStream is)
return Collections.unmodifiableList(certList);
}

/*
* Reads the entire contents of an InputStream into a byte array.
*
* @param is the InputStream to read from
* @return the bytes read from the InputStream
*/
private static byte[] readAllBytes(InputStream is) throws IOException {
byte[] buffer = new byte[8192];
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
int n;
while ((n = is.read(buffer)) != -1) {
baos.write(buffer, 0, n);
}
return baos.toByteArray();
}

/**
* Returns the encoded form of this certification path, using the
* default encoding.
Expand Down

1 comment on commit 0ca74f5

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.