-
Notifications
You must be signed in to change notification settings - Fork 71
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
Make key slot release implicit #59
Conversation
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.
Having a struct for key handles operations looks nicer ✨!
|
||
/// Wrapper around raw `psa_key_handle_t` which allows for easier manipulation of | ||
/// handles and the attributes associated with them. | ||
pub struct Key<'a>(psa_key_handle_t, &'a Mutex<()>); |
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.
Maybe it should be KeyHandle
?
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.
That's how it was named initially, but I renamed it because I thought an operation called get_key_attributes
sounds a bit weird for a key handle.
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.
Fair enough!
/// Release the key stored under this handle. | ||
pub fn release_key(&mut self) { | ||
unsafe { | ||
let _guard = self.1.lock().expect("Grabbing key handle mutex failed"); |
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 am wondering if there are any implications/safety concerns of putting a safe statement inside an unsafe
block? Maybe that could be outside of it and still work?
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'll have a look through the Nomicon again, see what they think
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 was thinking that if one of those safe function that we put in an unsafe
block suddendly become unsafe
, then we will still execute them without any warning 😕
But I do not know if that can happen
src/providers/mbed_provider/utils.rs
Outdated
|
||
impl Drop for Key<'_> { | ||
fn drop(&mut self) { | ||
if self.0 != 0 { |
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.
Will the psa_close_key
fail if the handle is 0
? Maybe that check could be put in the release_key
function if so.
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.
Not sure it does - we don't check the return status for close_key
anyway! But we could put a check in release_key
too.
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 updated - now the check is done in release_key
which is called every time a Key
is dropped
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.
Shall update tomorrow
This commit adds functionality to ensure that when key handles are dropped in the Mbed Provider, the slot is released automatically. Thus, there is no need to explicitly close handles anymore. Signed-off-by: Ionut Mihalcea <ionut.mihalcea@arm.com>
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.
Thanks for the change. We discussed that a new issue will be raised independently to look at our unsafe
blocks.
Key slots are now ✨automagically✨ released when the
Key
object is dropped.Resolves #57