@@ -60,6 +60,7 @@ int main(int argc, char** argv)
6060 RsaKey * pRsaKey = NULL ;
6161 WC_RNG rng ;
6262 int ret = 0 ;
63+ int result = 0 ;
6364 int bits = DEF_RSA_KEY_SIZE ;
6465 int sz ;
6566 unsigned char derBuf [MAX_DER_SIZE ];
@@ -184,19 +185,22 @@ int main(int argc, char** argv)
184185 /* Generate an RSA key pair. */
185186 if (wc_MakeRsaKey (pRsaKey , bits , WC_RSA_EXPONENT , & rng ) != 0 ) {
186187 printf ("failed to create rsa key\n" );
188+ result = -1 ;
187189 }
188190 else {
189191 /* Open public key file. */
190192 f = fopen (pubKey , "wb" );
191193 printf ("writing public key to %s\n" , pubKey );
192194 if (f == NULL ) {
193195 printf ("unable to write out public key\n" );
196+ result = -1 ;
194197 }
195198 else {
196199 /* Encode public key to DER. */
197200 sz = wc_RsaKeyToPublicDer (pRsaKey , derBuf , sizeof (derBuf ));
198201 if (sz <= 0 ) {
199202 printf ("error with rsa to public der %d\n" , sz );
203+ result = -1 ;
200204 }
201205 else {
202206 /* Write DER encoded public key to file. */
@@ -207,15 +211,17 @@ int main(int argc, char** argv)
207211
208212 /* Open private key file. */
209213 f = fopen (privKey , "wb" );
210- printf ("writing public key to %s\n" , privKey );
214+ printf ("writing private key to %s\n" , privKey );
211215 if (f == NULL ) {
212- printf ("unable to write out public key\n" );
216+ printf ("unable to write out private key\n" );
217+ result = -1 ;
213218 }
214219 else {
215220 /* Encode private key to DER. */
216221 sz = wc_RsaKeyToDer (pRsaKey , derBuf , sizeof (derBuf ));
217222 if (sz <= 0 ) {
218- printf ("error with rsa to public der %d\n" , sz );
223+ printf ("error with rsa to private der %d\n" , sz );
224+ result = -1 ;
219225 }
220226 else {
221227 /* Write DER encoded private key to file. */
@@ -231,7 +237,7 @@ int main(int argc, char** argv)
231237 free (pRsaKey );
232238 wolfSSL_Cleanup ();
233239
234- return 0 ;
240+ return result ;
235241#else
236242 (void )kRsaPubKey ;
237243 (void )kRsaPrivKey ;
0 commit comments