Merge 347e6f3db7
into 95051052b3
This commit is contained in:
commit
67d61ea3e0
2 changed files with 50 additions and 21 deletions
|
@ -107,34 +107,27 @@ int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b)
|
|||
|
||||
int X509_ALGOR_copy(X509_ALGOR *dest, const X509_ALGOR *src)
|
||||
{
|
||||
X509_ALGOR* tmp = NULL;
|
||||
if (src == NULL || dest == NULL)
|
||||
return 0;
|
||||
|
||||
if (dest->algorithm)
|
||||
ASN1_OBJECT_free(dest->algorithm);
|
||||
dest->algorithm = NULL;
|
||||
if (src == dest)
|
||||
return 1;
|
||||
|
||||
if (dest->parameter)
|
||||
ASN1_TYPE_free(dest->parameter);
|
||||
dest->parameter = NULL;
|
||||
tmp = X509_ALGOR_dup(src);
|
||||
if (tmp == NULL)
|
||||
return 0;
|
||||
|
||||
ASN1_OBJECT_free(dest->algorithm);
|
||||
dest->algorithm = tmp->algorithm;
|
||||
|
||||
if (src->algorithm)
|
||||
if ((dest->algorithm = OBJ_dup(src->algorithm)) == NULL)
|
||||
return 0;
|
||||
ASN1_TYPE_free(dest->parameter);
|
||||
dest->parameter = tmp->parameter;
|
||||
|
||||
if (src->parameter != NULL) {
|
||||
dest->parameter = ASN1_TYPE_new();
|
||||
if (dest->parameter == NULL)
|
||||
return 0;
|
||||
|
||||
/* Assuming this is also correct for a BOOL.
|
||||
* set does copy as a side effect.
|
||||
*/
|
||||
if (ASN1_TYPE_set1(dest->parameter, src->parameter->type,
|
||||
src->parameter->value.ptr) == 0)
|
||||
return 0;
|
||||
}
|
||||
tmp->algorithm = NULL;
|
||||
tmp->parameter = NULL;
|
||||
|
||||
X509_ALGOR_free(tmp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -211,6 +211,41 @@ static int test_spki_file(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int test_x509_algo(void)
|
||||
{
|
||||
int ret = 0;
|
||||
X509_ALGOR *algo = NULL;
|
||||
X509_ALGOR *algo_second = NULL;
|
||||
const EVP_MD* md = EVP_get_digestbyname("sha256");
|
||||
|
||||
if (md == NULL)
|
||||
goto err;
|
||||
if ((algo = X509_ALGOR_new()) == NULL)
|
||||
goto err;
|
||||
if ((algo->algorithm = OBJ_nid2obj(EVP_MD_get_type(md))) == NULL)
|
||||
goto err;
|
||||
if ((algo->parameter = ASN1_TYPE_new()) == NULL)
|
||||
goto err;
|
||||
algo->parameter->type = V_ASN1_NULL;
|
||||
|
||||
if(TEST_int_eq(X509_ALGOR_copy(algo, NULL), 0))
|
||||
goto err;
|
||||
if(TEST_int_eq(X509_ALGOR_copy(NULL, algo), 0))
|
||||
goto err;
|
||||
if(TEST_int_eq(X509_ALGOR_copy(algo, algo), 1))
|
||||
goto err;
|
||||
if(TEST_int_eq(X509_ALGOR_copy(algo_second, algo), 1))
|
||||
goto err;
|
||||
if(TEST_int_eq(X509_ALGOR_cmp(algo_second, algo), 0))
|
||||
goto err;
|
||||
|
||||
ret = 1;
|
||||
err:
|
||||
X509_ALGOR_free(algo);
|
||||
X509_ALGOR_free(algo_second);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int test_x509_files(void)
|
||||
{
|
||||
X509 *eecert = NULL, *cacert = NULL;
|
||||
|
@ -322,6 +357,7 @@ int setup_tests(void)
|
|||
|
||||
if (x509)
|
||||
ADD_TEST(test_x509_files);
|
||||
ADD_TEST(test_x509_algo);
|
||||
if (spki)
|
||||
ADD_TEST(test_spki_file);
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue