diff options
author | Richard Levitte <levitte@openssl.org> | 2020-07-28 22:00:09 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-08-24 10:02:26 +0200 |
commit | ab00ddb55907317d6cece552d12ddf3263c01043 (patch) | |
tree | 8190173cf3aa3f5a5789dbc3993a2d580e69402e /crypto/params.c | |
parent | c4fc564d48456be622509886d3ea5618fce2a02e (diff) | |
download | openssl-ab00ddb55907317d6cece552d12ddf3263c01043.tar.gz |
OSSL_PARAM: Add string pointer getters
When some function receives an OSSL_PARAM array to pilfer for data,
and there is a string of some sort, and all the code needs is to get
the pointer to the data, rather than a copy, there is currently no
other way than to use |param->data| directly. This is of course a
valid method, but lacks any safety check (is |param->data_type|
correct, for example?).
OSSL_PARAM_get_utf8_string_ptr() and OSSL_PARAM_get_octet_string_ptr()
helps the programmer with such things, by setting the argument pointer
to |param->data|.
Additionally, the handle the data types OSSL_PARAM_UTF8_PTR and
OSSL_PARAM_OCTET_PTR as well.
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/12512)
Diffstat (limited to 'crypto/params.c')
-rw-r--r-- | crypto/params.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/crypto/params.c b/crypto/params.c index 67ca4f0c83..4f7e25e0ca 100644 --- a/crypto/params.c +++ b/crypto/params.c @@ -969,3 +969,29 @@ OSSL_PARAM OSSL_PARAM_construct_end(void) return end; } + +static int get_string_ptr_internal(const OSSL_PARAM *p, const void **val, + size_t *used_len, unsigned int type) +{ + if (val == NULL || p == NULL || p->data_type != type) + return 0; + if (used_len != NULL) + *used_len = p->data_size; + *val = p->data; + return 1; +} + +int OSSL_PARAM_get_utf8_string_ptr(const OSSL_PARAM *p, const char **val) +{ + return OSSL_PARAM_get_utf8_ptr(p, val) + || get_string_ptr_internal(p, (const void **)val, NULL, + OSSL_PARAM_UTF8_STRING); +} + +int OSSL_PARAM_get_octet_string_ptr(const OSSL_PARAM *p, const void **val, + size_t *used_len) +{ + return OSSL_PARAM_get_octet_ptr(p, val, used_len) + || get_string_ptr_internal(p, val, used_len, OSSL_PARAM_OCTET_STRING); +} + |