Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix psa_generate_key(): return PSA_ERROR_INVALID_ARGUMENT for public key #5037
Fix psa_generate_key(): return PSA_ERROR_INVALID_ARGUMENT for public key #5037
Changes from 4 commits
c0fe820
770153e
d9d630c
25f7063
b576c7b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
NotSupported.test_cases_for_key_type_not_supported
, the test for is-a-public-key is a bit different (kt.name.endswith('_PUBLIC_KEY')
). I'm working on a follow-up that adds a methodkt.is_public()
. It would be better to have a single place that implements the test “is this key type for a public key?”, otherwise they risk diverging. Can you arrange to pass the information “is public key” down to this function?Or maybe it would be better to have a completely separate function for the invalid-argument-for-public key case? I find this function rather messy. That's unavoidable to some extent because we want to produce output that has a lot of tweakable parts. Here, I suspect that keeping
test_case_for_key_type_not_supported
as it originally was, and making a separate function for the new case invalid-argument-for-public key, would make the code easier to maintain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to confirm if I understand correctly your proposition:
test_case_for_key_type_not_supported()
test_case_for_key_type_invalid_argument()
In this solution we would also require to modify
NotSupported class
(change it to NotSupported_InvalidArgumentor add
InvalidArgument class". What option you suggest?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's what I meant.
If we want to make this really clean, taking a high-level view, the job of
NotSupported
is to enumerate combinations of (key type, algorithm, operation) and generate test cases for when one of them is not supported. If a combination is inherently impossible, rather than not supported by the current configuration of the library, then it's notNotSupported
's job to handle this. #4444 will introduce the generation of negative test cases for impossible combinations, but only for operations on existing keys, not for key generation (and not for key import either, but there are no impossible combinations for import). This leaves a gap of impossible combinations for key generation, which are just the cases where the key type is a public key. So, to be clean, there should be a separateCreationFail
class (distinct fromNotSupported
andOpFail
).However, this is an evolving test script, we shouldn't expend too much energy on it. Since
NotSupported
already does much of the job ofCreationFail
, we can keep it doing that, with a comment explaining that it's doing a little extra job on the side.Despite my saing we shouldn't expend too much energy on this, I do still prefer to restore the original
test_case_for_key_type_not_supported
and make a separate function for the invalid-generate case. I see renamingNotSupported
as optional: not-supported is still its main job.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've filed #5060 as a follow-up. It's not a top priority, but it is something we'll need eventually and it's a well-defined task that both adds a feature to
generate_psa_tests.py
and, I think, will make it a bit better structured. So @mprse if you don't have a more urgent task, I suggest you pick it up next.