-
Notifications
You must be signed in to change notification settings - Fork 144
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
Smart pointer constructors for Secure Session #378
Conversation
Using legacy C++03 interface of Secure Session may be a bit hard with modern practices introduced by C++11. Let's provide a more idiomatic interface where Secure Session assumes ownership over the provided instance of "secure_session_callback_interface_t" via smart pointers. We do so using the shared_ptr instance. This allows both shared and unique ownership over the provided callback interface. For example, if the users need only get_public_key_for_id() interface then they can share an instance of secure_session_callback_interface_t between all Secure Sessions. However, if they need to use the transport interface (send_data/receive_data) then they are likely to provide a unique instance for each Secure Session. We keep the old non-owning constructor for backwards compatibility. However, we mark is deprecated to incite the users to move on to a more safe and idiomatic interface with smart pointers. We still need to test the old interface so silence the relevant warning in this file.
Let's wait for #379 to be merged and rerun the CI build with that. |
themispp::secure_session_t client_unique_moved = std::move(client_unique); | ||
|
||
sput_fail_if(client_shared_moved.is_established(), "using shared session", __LINE__); | ||
sput_fail_if(client_unique_moved.is_established(), "using unique session", __LINE__); |
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 be good to check that client_unique
is invalid after move. check bad case 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.
Done. I've added a check that secure session throws after being moved out. (This is true for client_shared
as well. Ownership over the transport does not matter here.)
Using legacy C++03 interface of Secure Session may be a bit hard with modern practices introduced by C++11. Let's provide a more idiomatic interface where Secure Session assumes ownership over the provided instance of
secure_session_callback_interface_t
via smart pointers.We do so using the shared_ptr instance. This allows both shared and unique ownership over the provided callback interface. For example, if the users need only
get_public_key_for_id
interface then they can share an instance ofsecure_session_callback_interface_t
between all Secure Sessions. However, if they need to use the transport interface (send_data
/receive_data
) then they are likely to provide a unique instance for each Secure Session.We keep the old non-owning constructor for backwards compatibility. However, we mark is deprecated to incite the users to move on to a more safe and idiomatic interface with smart pointers.
We still need to test the old interface so silence the relevant warning in this file.