-
Notifications
You must be signed in to change notification settings - Fork 40
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
Split ChannelCipher implementation into encrypt and decrypt specialisms #746
Conversation
I've also made the cipher get methods on ChannelOptions safe to be called from any thread.
…han one thread. I could have gone down the route of simplistic addition of locks to the encrypt and decrypt methods, but that would just have been a sticky plaster, probably hiding deeper routed architectural issues elsewhere in this codebase. By adding this lightweight check, we will see specific evidence that this particular problem is the fault if customers encounter this.
…ning the cipher from crypto implementation. A mistake made by me in my refactor.
I think the failure I'm currently seeing is 'my fault', being something new since the changes I made... however, I suspect that it may be related to a problem we recently saw elsewhere: ably/ably-cocoa#1266 I'll iterate further on this tomorrow.
|
…lementation. This was the reason for the failing tests, where the tests were using 'default cipher params' which means a randomly generated encryption key (RSE1). Having split the encipher and decipher apart, I had broken the implicit linkage between the two for that scenario (i.e. from ChannelOptions where cipherParams was null).
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.
When I was going through code, I wasn't sure whether we should explicitly say that a method will throw ConcurrentModificationException, but I can see that this is actually thrown when another thread tries to acquire access. So it might as well be a good idea to keep it. I am going to request change in order to clarify this.
I had forgotten that I had moved this into the single method that was using it.
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.
LGTM
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.
Overall looks good but we can improve it further 😉 I love the fact that you've applied the interface segregation principle and created multiple smaller interfaces instead of the big one 😁
…hannelCipher interface, deprecating them. There might have been customers using this method, as it was technically public API even though it was annotated (in plain text) as 'Internal'.
It was ChannelOptions' getCipher() which potentially needed legacy support.
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.
LGTM 👍
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.
LGTM
I've made the cipher get method on
ChannelOptions
safe to be called from any thread.I've also added a lightweight protection to each cipher implementation to fail early with a
ConcurrentModificationException
if the cipher is asked to operate from multiple threads concurrently.This refactor ended up being a little larger than I had originally anticipated, but I feel that this area of the codebase is now clearer to follow and reason about. There is more I could have tackled but it fell outside of the scope of solving this particular grey area.
Fixes #741.