update wolfSSL_i2d_RSAPrivateKey function

This commit is contained in:
Jacob Barthelmeh
2019-03-28 14:15:57 -06:00
parent 15c7463150
commit b599dc2b9d
2 changed files with 28 additions and 7 deletions

View File

@@ -29167,7 +29167,11 @@ WOLFSSL_RSA *wolfSSL_d2i_RSAPrivateKey(WOLFSSL_RSA **r,
#if !defined(HAVE_FAST_RSA)
/* Converts an internal RSA structure to DER format.
Returns size of DER on success and WOLFSSL_FAILURE if error */
* If "pp" is null then buffer size only is returned.
* If "*pp" is null then a created buffer is set in *pp and the caller is
* responsible for free'ing it.
* Returns size of DER on success and WOLFSSL_FAILURE if error
*/
int wolfSSL_i2d_RSAPrivateKey(WOLFSSL_RSA *rsa, unsigned char **pp)
{
#if defined(WOLFSSL_KEY_GEN)
@@ -29179,7 +29183,7 @@ int wolfSSL_i2d_RSAPrivateKey(WOLFSSL_RSA *rsa, unsigned char **pp)
WOLFSSL_ENTER("wolfSSL_i2d_RSAPrivateKey");
/* check for bad functions arguments */
if ((rsa == NULL) || (pp == NULL)) {
if (rsa == NULL) {
WOLFSSL_MSG("Bad Function Arguments");
return BAD_FUNC_ARG;
}
@@ -29210,12 +29214,23 @@ int wolfSSL_i2d_RSAPrivateKey(WOLFSSL_RSA *rsa, unsigned char **pp)
return ret;
}
if (pp != NULL) {
if (*pp == NULL) {
/* create buffer and return it */
*pp = (unsigned char*)XMALLOC(ret, NULL, DYNAMIC_TYPE_OPENSSL);
if (*pp == NULL) {
return WOLFSSL_FATAL_ERROR;
}
XMEMCPY(*pp, der, ret);
}
else {
/* ret is the size of the DER buffer */
for (i = 0; i < ret; i++) {
*(*pp + i) = *(der + i);
}
*pp += ret;
}
}
XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret; /* returns size of DER if successful */
#else

View File

@@ -20744,8 +20744,14 @@ static void test_wolfSSL_d2i_PrivateKeys_bio(void)
/*i2d RSAprivate key tests */
AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), BAD_FUNC_ARG);
AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192);
AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
sizeof_client_key_der_2048);
bufPtr = NULL;
AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr),
sizeof_client_key_der_2048);
AssertNotNull(bufPtr);
free(bufPtr);
#endif /* USE_CERT_BUFFERS_2048 WOLFSSL_KEY_GEN */
RSA_free(rsa);
#endif /* NO_RSA */