@@ -68,13 +68,15 @@ public void testWolfSSLCertificate() throws WolfSSLException {
6868 test_WolfSSLCertificate_new_pemArray ();
6969 test_runCertTestsAfterConstructor ();
7070
71- /* WolfSSLCertificate(byte[] pem) */
72- test_WolfSSLCertificate_new_derFile ();
73- test_runCertTestsAfterConstructor ();
74-
75- /* WolfSSLCertificate(String pem) */
76- test_WolfSSLCertificate_new_pemFile ();
77- test_runCertTestsAfterConstructor ();
71+ if (WolfSSL .FileSystemEnabled () == true ) {
72+ /* WolfSSLCertificate(byte[] pem) */
73+ test_WolfSSLCertificate_new_derFile ();
74+ test_runCertTestsAfterConstructor ();
75+
76+ /* WolfSSLCertificate(String pem) */
77+ test_WolfSSLCertificate_new_pemFile ();
78+ test_runCertTestsAfterConstructor ();
79+ }
7880 }
7981
8082
@@ -191,6 +193,19 @@ public void test_WolfSSLCertificate_new_pemFile() {
191193 System .out .println ("\t ... passed" );
192194 }
193195
196+ private byte [] fileToByteArray (String filePath )
197+ throws IOException {
198+ File f = new File (filePath );
199+ byte [] fBytes = null ;
200+
201+ InputStream stream = new FileInputStream (f );
202+ fBytes = new byte [(int ) f .length ()];
203+ stream .read (fBytes , 0 , fBytes .length );
204+ stream .close ();
205+
206+ return fBytes ;
207+ }
208+
194209
195210 public void test_getSerial () {
196211 byte [] expected = new byte []{
@@ -501,7 +516,13 @@ public void test_getKeyUsage() {
501516 int i ;
502517 boolean [] kuse ;
503518
504- ext = new WolfSSLCertificate (this .external );
519+ if (WolfSSL .FileSystemEnabled () == true ) {
520+ ext = new WolfSSLCertificate (this .external );
521+ } else {
522+ ext = new WolfSSLCertificate (fileToByteArray (this .external ),
523+ WolfSSL .SSL_FILETYPE_ASN1 );
524+ }
525+
505526 kuse = ext .getKeyUsage ();
506527 if (kuse == null ) {
507528 System .out .println ("\t \t ... failed" );
@@ -516,8 +537,9 @@ public void test_getKeyUsage() {
516537 }
517538 }
518539 ext .free ();
519- } catch (WolfSSLException ex ) {
520- Logger .getLogger (WolfSSLCertificateTest .class .getName ()).log (Level .SEVERE , null , ex );
540+ } catch (Exception ex ) {
541+ Logger .getLogger (WolfSSLCertificateTest .class .getName ()).log (
542+ Level .SEVERE , null , ex );
521543 System .out .println ("\t \t ... failed" );
522544 fail ("Error loading external certificate" );
523545 }
0 commit comments