@@ -537,14 +537,31 @@ static void test_wolfSSH_CTX_UsePrivateKey_buffer(void)
537537{
538538#ifndef WOLFSSH_NO_SERVER
539539 WOLFSSH_CTX * ctx ;
540+ #ifdef HAVE_ECC
540541 byte * eccKey ;
542+ word32 eccKeySz ;
543+ #endif
544+ #ifndef NO_RSA
541545 byte * rsaKey ;
542- byte * lastKey ;
543- word32 eccKeySz , rsaKeySz , lastKeySz ;
544-
545- AssertIntEQ (0 , ConvertHexToBin (serverKeyEccDer , & eccKey , & eccKeySz ,
546- serverKeyRsaDer , & rsaKey , & rsaKeySz ,
547- NULL , NULL , NULL , NULL , NULL , NULL ));
546+ word32 rsaKeySz ;
547+ #endif
548+ byte * lastKey = NULL ;
549+ word32 lastKeySz = 0 ;
550+
551+ #ifdef HAVE_ECC
552+ AssertIntEQ (0 ,
553+ ConvertHexToBin (serverKeyEccDer , & eccKey , & eccKeySz ,
554+ NULL , NULL , NULL ,
555+ NULL , NULL , NULL ,
556+ NULL , NULL , NULL ));
557+ #endif
558+ #ifndef NO_RSA
559+ AssertIntEQ (0 ,
560+ ConvertHexToBin (serverKeyRsaDer , & rsaKey , & rsaKeySz ,
561+ NULL , NULL , NULL ,
562+ NULL , NULL , NULL ,
563+ NULL , NULL , NULL ));
564+ #endif
548565
549566 AssertNotNull (ctx = wolfSSH_CTX_new (WOLFSSH_ENDPOINT_SERVER , NULL ));
550567 AssertNull (ctx -> privateKey );
@@ -568,7 +585,7 @@ static void test_wolfSSH_CTX_UsePrivateKey_buffer(void)
568585 /* Fail: ctx set, key set, others bad */
569586 AssertIntNE (WS_SUCCESS ,
570587 wolfSSH_CTX_UsePrivateKey_buffer (ctx ,
571- rsaKey , 0 , TEST_BAD_FORMAT_NEXT ));
588+ lastKey , 0 , TEST_BAD_FORMAT_NEXT ));
572589 AssertNull (ctx -> privateKey );
573590 AssertIntEQ (0 , ctx -> privateKeySz );
574591 AssertIntEQ (0 , ctx -> useEcc );
@@ -582,39 +599,49 @@ static void test_wolfSSH_CTX_UsePrivateKey_buffer(void)
582599
583600 /* Fail: ctx set, key set, keySz set, format invalid */
584601 AssertIntNE (WS_SUCCESS , wolfSSH_CTX_UsePrivateKey_buffer (ctx ,
585- rsaKey , rsaKeySz , TEST_GOOD_FORMAT_PEM ));
602+ lastKey , lastKeySz , TEST_GOOD_FORMAT_PEM ));
586603 AssertNull (ctx -> privateKey );
587604 AssertIntEQ (0 , ctx -> privateKeySz );
588605 AssertIntEQ (0 , ctx -> useEcc );
589606
590607 /* Pass */
608+ #ifdef HAVE_ECC
609+ lastKey = ctx -> privateKey ;
610+ lastKeySz = ctx -> privateKeySz ;
611+
591612 AssertIntEQ (WS_SUCCESS ,
592613 wolfSSH_CTX_UsePrivateKey_buffer (ctx , eccKey , eccKeySz ,
593614 TEST_GOOD_FORMAT_ASN1 ));
594615 AssertNotNull (ctx -> privateKey );
595616 AssertIntNE (0 , ctx -> privateKeySz );
596- #ifndef WOLFSSH_NO_ECDSA
597617 AssertIntEQ (serverKeyEccCurveId , ctx -> useEcc );
618+
619+ AssertIntEQ (0 , (lastKey == ctx -> privateKey ));
620+ AssertIntNE (lastKeySz , ctx -> privateKeySz );
598621#endif
599622
600- #ifndef WOLFSSH_NO_RSA
623+ #ifndef NO_RSA
601624 lastKey = ctx -> privateKey ;
602625 lastKeySz = ctx -> privateKeySz ;
626+
603627 AssertIntEQ (WS_SUCCESS ,
604628 wolfSSH_CTX_UsePrivateKey_buffer (ctx , rsaKey , rsaKeySz ,
605629 TEST_GOOD_FORMAT_ASN1 ));
606630 AssertNotNull (ctx -> privateKey );
607631 AssertIntNE (0 , ctx -> privateKeySz );
608632 AssertIntEQ (0 , ctx -> useEcc );
633+
609634 AssertIntEQ (0 , (lastKey == ctx -> privateKey ));
610635 AssertIntNE (lastKeySz , ctx -> privateKeySz );
611- #else
612- (void )lastKey ;
613- (void )lastKeySz ;
614636#endif
615637
616638 wolfSSH_CTX_free (ctx );
617- FreeBins (eccKey , rsaKey , NULL , NULL );
639+ #ifdef HAVE_ECC
640+ FreeBins (eccKey , NULL , NULL , NULL );
641+ #endif
642+ #ifndef NO_RSA
643+ FreeBins (rsaKey , NULL , NULL , NULL );
644+ #endif
618645#endif /* WOLFSSH_NO_SERVER */
619646}
620647
0 commit comments