Skip to content
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

Merged
merged 4 commits into from
Feb 14, 2019

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented Feb 13, 2019

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.

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.
@ilammy ilammy added the W-ThemisPP ⚔️ Wrapper: ThemisPP, C++ API label Feb 13, 2019
@ilammy
Copy link
Collaborator Author

ilammy commented Feb 13, 2019

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__);
Copy link
Collaborator

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)

Copy link
Collaborator Author

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.)

@ilammy ilammy merged commit e8c9ee3 into cossacklabs:master Feb 14, 2019
@ilammy ilammy deleted the themispp-ownership branch February 19, 2019 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
W-ThemisPP ⚔️ Wrapper: ThemisPP, C++ API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants