Refactor OSSL_PARAM_allocate_from_text() for better flexibility#11046
Refactor OSSL_PARAM_allocate_from_text() for better flexibility#11046levitte wants to merge 7 commits intoopenssl:masterfrom
Conversation
|
Travis red cross is relevant (duplicated NOTES section) |
Thanks. Fixed |
paulidale
left a comment
There was a problem hiding this comment.
All this change for one instance where the return is used?
I'm dubious as to the value this provides.
Is it possible to instead consider a sequence like:
if ((p = OSSL_PARAM_locate_const(setable, "name")) == NULL)
return -2;
if (!OSSL_PARAM_allocate_from_text(¶ms[0], p, name, value, strlen(value)))
return 0;
It's less of a kludge, the same number of lines of code, clearer and no slower.
|
@paulidale, I was going to suggest exactly what you suggest, until I realised that it's not that simple, the caller must then also deal with any key variant (such as names prefixed with "hex"). As for only one spot, I'm pretty sure we have more than one ctrl_str function, no? I haven't looked at the others yet. |
|
Good point about the hex version. I still think returning the information via a misused structure field isn't ideal. Is a |
|
The function would be: OSSL_PARAM *ossl_param_locate_ctrl_str(const OSSL_PARAM *paramdefs,
const char *key, int *ishex)
{
*ishex = strncmp(key, "hex", 3) == 0;
if (*ishex)
key += 3;
return OSSL_PARAM_locate_const(paramdefs, key);
} |
|
This function is also used in apps/mac.c, and I really abhor having to use internal functions in the app. Eating our own dog food and all that. |
|
Either make the new function public or don't distinguish "unknown parameter" from other possible failures. I abhor magic flags which is what this boils down to. Changing the |
|
Re names, would you do with |
|
What about #11049 ? |
|
Damn it, I was warming up on the idea of a special locate function... |
|
It's only a suggestion. |
|
I have now reworked this to have a separate locator function. |
|
I think I've fixed the Travis failure. |
|
Not WIP any more, I'm quite satisfied with the result by now. Please review (or if you prefer #11049, please say so) |
paulidale
left a comment
There was a problem hiding this comment.
I wonder if this is over complicating a public API. For applications that don't care about the reason for failure OSSL_PARAM_allocate_from_text has become more complicated to use -- it's now two calls and an extra local variable is required.
I quite like that OSSL_PARAM_allocate_from_text did the search.
I prefer #11049 from a user's perspective.
|
BTW: most internal uses of |
9580cdb to
4d1e70c
Compare
|
Fixed Travis failures (C++ builds with our headers! I haven't seen those fail in a while... and that, just because I dared call a parameter |
|
As to the choice between this and #11049, don't ask me to make it. I'm obviously biased |
|
The more I think about it, the more I prefer the #11049 approach. I've a conflict of interest too. |
|
So, er, would someone else please step in and make a judgment call? @openssl |
|
Just my opinion: Although this PR is slightly cleaner architecturally from the callers POV I really prefer #11049 as being more simple to use. |
I agree with Tomas. API simplicity should win. |
|
An option for future expansion would be to return an unsigned value which contains flags rather than a found/not found Boolean. I can't think of a use for this but it would be more future proof. |
|
@paulidale, how does what you just wrote apply to this PR? |
|
It's for/about #11049 but the discussion is happening here... |
|
Yeah, that's not confusing at all... |
OSSL_PARAM_allocate_from_text() and OSSL_PARAM_construct_from_text() were "do-it-all" kind of functions, which didn't allow much flexibility in code that wants to adapt to situations such as the key not being found in the descriptor OSSL_PARAM array. We therefore split the functionality to make key lookup and value processing two different functions, thus resulting in the following functions: - OSSL_PARAM_parse_locate_const(), which parses the key and sets flags accordingly, but otherwise works like OSSL_PARAM_locate_const(). - OSSL_PARAM_construct_from_text(), which doesn't look up the key any more, but rather only parses the given value, with direction from a template OSSL_PARAM item, which could come from a call of OSSL_PARAM_parse_locate_const(). - OSSL_PARAM_allocate_from_text(), which is modified exactly like OSSL_PARAM_construct_from_text(). With this split, callers can also ignore OSSL_PARAM_parse_locate_const() completely, and work with an descriptor OSSL_PARAM item of their own choosing.
Now that locating the key in the settables is done with OSSL_PARAM_parse_locate_const(), legacy_ctrl_str_to_param() has enough information to return -2 when the given key isn't supported.
C++ (enable-buildtest-c++) didn't quite like a parameter named 'template' wonder why... ;-)
90a6592 to
4c1bb78
Compare
|
Choice made: #11049 (review) |
OSSL_PARAM_allocate_from_text() and OSSL_PARAM_construct_from_text()
were "do-it-all" kind of functions, which didn't allow much
flexibility in code that wants to adapt to situations such as the key
not being found in the descriptor OSSL_PARAM array.
We therefore split the functionality to make key lookup and value
processing two different functions, thus resulting in the following
functions:
accordingly, but otherwise works like OSSL_PARAM_locate_const().
more, but rather only parses the given value, with direction from a
template OSSL_PARAM item, which could come from a call of
OSSL_PARAM_parse_locate_const().
OSSL_PARAM_construct_from_text().
With this split, callers can also ignore OSSL_PARAM_parse_locate_const()
completely, and work with an descriptor OSSL_PARAM item of their own
choosing.