diff options
author | Matt Caswell <matt@openssl.org> | 2021-05-07 16:42:53 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2021-05-20 09:28:38 +0100 |
commit | e2ed740ec4dcfd32723d849a146bfc126b95d16c (patch) | |
tree | 6b8d1e59a96b14cd7e8170c0f6ee2d260584eb04 /crypto/property/property_string.c | |
parent | 87e4e9c473dd3305cb98b37c672edff8ddb436de (diff) |
Implement the ability to convert a PROPERTY_LIST to a string
We have the ability to parse a string into a PROPERTY_LIST already. Now
we have the ability to go the other way.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15242)
Diffstat (limited to 'crypto/property/property_string.c')
-rw-r--r-- | crypto/property/property_string.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/crypto/property/property_string.c b/crypto/property/property_string.c index 9eb55cb461..06f58496db 100644 --- a/crypto/property/property_string.c +++ b/crypto/property/property_string.c @@ -162,6 +162,45 @@ OSSL_PROPERTY_IDX ossl_property_name(OSSL_LIB_CTX *ctx, const char *s, s); } +struct find_str_st { + const char *str; + OSSL_PROPERTY_IDX idx; +}; + +static void find_str_fn(PROPERTY_STRING *prop, void *vfindstr) +{ + struct find_str_st *findstr = vfindstr; + + if (prop->idx == findstr->idx) + findstr->str = prop->s; +} + +static const char *ossl_property_str(int name, OSSL_LIB_CTX *ctx, + OSSL_PROPERTY_IDX idx) +{ + struct find_str_st findstr; + PROPERTY_STRING_DATA *propdata + = ossl_lib_ctx_get_data(ctx, OSSL_LIB_CTX_PROPERTY_STRING_INDEX, + &property_string_data_method); + + if (propdata == NULL) + return NULL; + + findstr.str = NULL; + findstr.idx = idx; + + lh_PROPERTY_STRING_doall_arg(name ? propdata->prop_names + : propdata->prop_values, + find_str_fn, &findstr); + + return findstr.str; +} + +const char *ossl_property_name_str(OSSL_LIB_CTX *ctx, OSSL_PROPERTY_IDX idx) +{ + return ossl_property_str(1, ctx, idx); +} + OSSL_PROPERTY_IDX ossl_property_value(OSSL_LIB_CTX *ctx, const char *s, int create) { @@ -175,3 +214,8 @@ OSSL_PROPERTY_IDX ossl_property_value(OSSL_LIB_CTX *ctx, const char *s, create ? &propdata->prop_value_idx : NULL, s); } + +const char *ossl_property_value_str(OSSL_LIB_CTX *ctx, OSSL_PROPERTY_IDX idx) +{ + return ossl_property_str(0, ctx, idx); +} |