Add convenience functions EVP_str2ctrl() and EVP_hex2ctrl()
These functions are generalizations of EVP_PKEY_CTX_str2ctrl() and EVP_PKEY_CTX_hex2ctrl(). They will parse the value, and then pass the parsed result and length to a callback that knows exactly how to pass them on to a main _ctrl function, along with a context structure pointer. Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/7393)
This commit is contained in:
parent
2bdb4af503
commit
f842b6b2a4
3 changed files with 37 additions and 0 deletions
|
@ -526,3 +526,30 @@ int EVP_CIPHER_CTX_test_flags(const EVP_CIPHER_CTX *ctx, int flags)
|
|||
{
|
||||
return (ctx->flags & flags);
|
||||
}
|
||||
|
||||
int EVP_str2ctrl(int (*cb)(void *ctx, int cmd, void *buf, size_t buflen),
|
||||
void *ctx, int cmd, const char *value)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlen(value);
|
||||
if (len > INT_MAX)
|
||||
return -1;
|
||||
return cb(ctx, cmd, (void *)value, len);
|
||||
}
|
||||
|
||||
int EVP_hex2ctrl(int (*cb)(void *ctx, int cmd, void *buf, size_t buflen),
|
||||
void *ctx, int cmd, const char *hex)
|
||||
{
|
||||
unsigned char *bin;
|
||||
long binlen;
|
||||
int rv = -1;
|
||||
|
||||
bin = OPENSSL_hexstr2buf(hex, &binlen);
|
||||
if (bin == NULL)
|
||||
return 0;
|
||||
if (binlen <= INT_MAX)
|
||||
rv = cb(ctx, cmd, bin, binlen);
|
||||
OPENSSL_free(bin);
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -1670,6 +1670,14 @@ void EVP_PKEY_meth_get_digest_custom(EVP_PKEY_METHOD *pmeth,
|
|||
EVP_MD_CTX *mctx));
|
||||
void EVP_add_alg_module(void);
|
||||
|
||||
/*
|
||||
* Convenient helper functions to transfer string based controls.
|
||||
* The callback gets called with the parsed value.
|
||||
*/
|
||||
int EVP_str2ctrl(int (*cb)(void *ctx, int cmd, void *buf, size_t buflen),
|
||||
void *ctx, int cmd, const char *value);
|
||||
int EVP_hex2ctrl(int (*cb)(void *ctx, int cmd, void *buf, size_t buflen),
|
||||
void *ctx, int cmd, const char *hex);
|
||||
|
||||
# ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -4595,3 +4595,5 @@ EVP_MAC_nid 4548 1_1_2 EXIST::FUNCTION:
|
|||
EVP_get_macbyname 4549 1_1_2 EXIST::FUNCTION:
|
||||
EVP_MAC_do_all 4550 1_1_2 EXIST::FUNCTION:
|
||||
EVP_MAC_do_all_sorted 4551 1_1_2 EXIST::FUNCTION:
|
||||
EVP_str2ctrl 4552 1_1_2 EXIST::FUNCTION:
|
||||
EVP_hex2ctrl 4553 1_1_2 EXIST::FUNCTION:
|
||||
|
|
Loading…
Reference in a new issue