1515 */
1616package nl .altindag .ssl .pem .util ;
1717
18+ import nl .altindag .laleler .IOUtils ;
19+ import nl .altindag .laleler .ValidationUtils ;
1820import nl .altindag .ssl .SSLFactory ;
1921import nl .altindag .ssl .exception .GenericIOException ;
2022import nl .altindag .ssl .pem .decryptor .PemDecryptor ;
2527import nl .altindag .ssl .pem .exception .PublicKeyParseException ;
2628import nl .altindag .ssl .util .KeyManagerUtils ;
2729import nl .altindag .ssl .util .TrustManagerUtils ;
28- import nl .altindag .ssl .util .internal .IOUtils ;
29- import nl .altindag .ssl .util .internal .ValidationUtils ;
3030import org .bouncycastle .asn1 .pkcs .PrivateKeyInfo ;
3131import org .bouncycastle .cert .X509CertificateHolder ;
3232import org .bouncycastle .cert .jcajce .JcaX509CertificateConverter ;
7171
7272import static nl .altindag .ssl .pem .util .PemType .CERTIFICATE ;
7373import static nl .altindag .ssl .pem .util .PemType .KEY ;
74- import static nl .altindag .ssl . util . internal .CollectorsUtils .toListAndThen ;
75- import static nl .altindag .ssl . util . internal .CollectorsUtils .toUnmodifiableList ;
76- import static nl .altindag .ssl . util . internal .ValidationUtils .requireNotEmpty ;
77- import static nl .altindag .ssl . util . internal .ValidationUtils .requireNotNull ;
74+ import static nl .altindag .laleler .CollectorsUtils .toListAndThen ;
75+ import static nl .altindag .laleler .CollectorsUtils .toUnmodifiableList ;
76+ import static nl .altindag .laleler .ValidationUtils .requireNotEmpty ;
77+ import static nl .altindag .laleler .ValidationUtils .requireNotNull ;
7878
7979/**
8080 * Reads PEM formatted private keys and certificates
@@ -160,7 +160,7 @@ public static List<X509Certificate> loadCertificate(String... certificatePaths)
160160 * Loads certificates from the filesystem and maps it to a list of {@link X509Certificate}
161161 */
162162 public static List <X509Certificate > loadCertificate (Path ... certificatePaths ) {
163- return loadCertificate (certificatePaths , IOUtils :: getFileAsStream );
163+ return loadCertificate (certificatePaths , path -> IOUtils . getFileAsStream ( path , GenericIOException :: new ) );
164164 }
165165
166166 /**
@@ -176,7 +176,7 @@ public static List<X509Certificate> loadCertificate(InputStream... certificateSt
176176 private static <T > List <X509Certificate > loadCertificate (T [] resources , Function <T , InputStream > resourceMapper ) {
177177 return Arrays .stream (resources )
178178 .map (resourceMapper )
179- .map (IOUtils :: getContent )
179+ .map (inputStream -> IOUtils . getContent ( inputStream , GenericIOException :: new ) )
180180 .map (PemUtils ::parseCertificate )
181181 .flatMap (Collection ::stream )
182182 .collect (toUnmodifiableList ());
@@ -297,7 +297,7 @@ public static X509ExtendedKeyManager loadIdentityMaterial(Path certificateChainP
297297 * from the filesystem and maps it to an instance of {@link X509ExtendedKeyManager}
298298 */
299299 public static X509ExtendedKeyManager loadIdentityMaterial (Path certificateChainPath , Path privateKeyPath , char [] keyPassword ) {
300- return loadIdentityMaterial (certificateChainPath , privateKeyPath , keyPassword , IOUtils :: getFileAsStream );
300+ return loadIdentityMaterial (certificateChainPath , privateKeyPath , keyPassword , path -> IOUtils . getFileAsStream ( path , GenericIOException :: new ) );
301301 }
302302
303303 /**
@@ -336,7 +336,7 @@ public static X509ExtendedKeyManager loadIdentityMaterial(Path identityPath) {
336336 * from the filesystem and maps it to an instance of {@link X509ExtendedKeyManager}
337337 */
338338 public static X509ExtendedKeyManager loadIdentityMaterial (Path identityPath , char [] keyPassword ) {
339- return loadIdentityMaterial (identityPath , keyPassword , IOUtils :: getFileAsStream );
339+ return loadIdentityMaterial (identityPath , keyPassword , path -> IOUtils . getFileAsStream ( path , GenericIOException :: new ) );
340340 }
341341
342342 /**
@@ -363,8 +363,8 @@ private static <T> X509ExtendedKeyManager loadIdentityMaterial(T certificateChai
363363 try (InputStream certificateChainStream = resourceMapper .apply (certificateChain );
364364 InputStream privateKeyStream = resourceMapper .apply (privateKey )) {
365365
366- String certificateChainContent = IOUtils .getContent (certificateChainStream );
367- String privateKeyContent = IOUtils .getContent (privateKeyStream );
366+ String certificateChainContent = IOUtils .getContent (certificateChainStream , GenericIOException :: new );
367+ String privateKeyContent = IOUtils .getContent (privateKeyStream , GenericIOException :: new );
368368
369369 return parseIdentityMaterial (certificateChainContent , privateKeyContent , keyPassword );
370370 } catch (IOException exception ) {
@@ -374,7 +374,7 @@ private static <T> X509ExtendedKeyManager loadIdentityMaterial(T certificateChai
374374
375375 private static <T > X509ExtendedKeyManager loadIdentityMaterial (T identity , char [] keyPassword , Function <T , InputStream > resourceMapper ) {
376376 try (InputStream identityStream = resourceMapper .apply (identity )) {
377- String identityContent = IOUtils .getContent (identityStream );
377+ String identityContent = IOUtils .getContent (identityStream , GenericIOException :: new );
378378 return parseIdentityMaterial (identityContent , identityContent , keyPassword );
379379 } catch (IOException exception ) {
380380 throw new GenericIOException (exception );
@@ -441,7 +441,7 @@ public static PrivateKey loadPrivateKey(Path identityPath) {
441441 * Loads the private key from the filesystem and maps it to an instance of {@link PrivateKey}
442442 */
443443 public static PrivateKey loadPrivateKey (Path identityPath , char [] keyPassword ) {
444- return loadPrivateKey (identityPath , keyPassword , IOUtils :: getFileAsStream );
444+ return loadPrivateKey (identityPath , keyPassword , path -> IOUtils . getFileAsStream ( path , GenericIOException :: new ) );
445445 }
446446
447447 /**
0 commit comments