Skip to content

Commit

Permalink
fixup! rand_lib.c: Factorize out an ossl_merge_queries() function
Browse files Browse the repository at this point in the history
  • Loading branch information
t8m committed Feb 10, 2025
1 parent 1416804 commit 1a8648a
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions crypto/property/property_aux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2025 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/

#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <openssl/err.h>
#include "internal/property.h"
#include "internal/propertyerr.h"

char *ossl_merge_queries(OSSL_LIB_CTX *libctx, const char *propq1,
const char *propq2)
{
OSSL_PROPERTY_LIST *pl1, *pl2, *mergedpl;
char *props;
size_t props_len;

if (propq1 == NULL) {
if (propq2 == NULL)
return NULL;
return OPENSSL_strdup(propq2);
} else if (propq2 == NULL) {
return OPENSSL_strdup(propq1);
}

pl1 = ossl_parse_query(libctx, propq1, 1);
if (pl1 == NULL) {
ERR_raise(ERR_LIB_PROP, PROP_R_INVALID_PROPERTY_QUERY);
return NULL;
}
pl2 = ossl_parse_query(libctx, propq2, 1);
if (pl2 == NULL) {
ossl_property_free(pl1);
ERR_raise(ERR_LIB_PROP, PROP_R_INVALID_PROPERTY_QUERY);
return NULL;
}
mergedpl = ossl_property_merge(pl2, pl1);
ossl_property_free(pl1);
ossl_property_free(pl2);
if (mergedpl == NULL) {
ERR_raise(ERR_LIB_PROP, ERR_R_INTERNAL_ERROR);
return NULL;
}
props_len = ossl_property_list_to_string(libctx, mergedpl, NULL, 0);
if (props_len == 0) {
ERR_raise(ERR_LIB_PROP, ERR_R_INTERNAL_ERROR);
goto err;
} else {
props = OPENSSL_malloc(props_len);
if (props == NULL)
goto err;
if (ossl_property_list_to_string(libctx, mergedpl,
props, props_len) == 0) {
ERR_raise(ERR_LIB_RAND, ERR_R_INTERNAL_ERROR);
goto err;
}
}

err:
ossl_property_free(mergedpl);
return props;
}

0 comments on commit 1a8648a

Please sign in to comment.