-
Notifications
You must be signed in to change notification settings - Fork 786
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
Change KeyBasedEncryptor's padding #1508
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1508 +/- ##
===========================================
- Coverage 42.99% 42.99% -0.01%
===========================================
Files 477 477
Lines 14175 14174 -1
===========================================
- Hits 6095 6094 -1
Misses 8080 8080
Continue to review full report at Codecov.
|
from monkey_island.cc.server_utils.encryption import KeyBasedEncryptor | ||
|
||
PLAINTEXT = "password" | ||
PLAINTEXT_UTF8 = "slaptažodis" # "password" in Lithuanian |
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 add some other characters like: љњќшжѓ or 的 必 弟 . Just to make sure.
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.
Looks good to me.
Just take a look at the UT comment.
def _pad(self, message: str) -> bytes: | ||
return Padding.pad(message.encode(), self._BLOCK_SIZE) | ||
|
||
def _unpad(self, message: str): | ||
return message[0 : -ord(message[len(message) - 1])] | ||
def _unpad(self, message: bytes) -> str: | ||
return Padding.unpad(message, self._BLOCK_SIZE).decode() |
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.
Since these functions are just thin wrappers, I suggest getting rid of them and inlining the calls to Padding
.
padded_plaintext = Padding.pad(...)
return base64.base64encode(cipher_iv + cipher.encrypt(padded_plaintext)).decode()
...
padded_plaintext = cipher.decrypt(...)
return Padding.unpad(padded_plaintext, self._block_size).decode()
def test_encrypt_decrypt_string_utf8_with_key(): | ||
encrypted = kb_encryptor.encrypt(PLAINTEXT_UTF8) | ||
decrypted = kb_encryptor.decrypt(encrypted) | ||
assert decrypted == PLAINTEXT_UTF8 |
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.
Let's add a test that encrypts plaintext that is exactly a multiple of _BLOCK_SIZE
in length.
This should get a changelog entry. We fixed a bug. |
…ple of block size in length
6fcb45d
to
19dad89
Compare
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.
We also have ж in Macedonian language. :)
Good job!
Catching this exception was a workaround for an issue that was resolved in PR #1508.
Catching this exception was a workaround for an issue that was resolved in PR #1508.
What does this PR do?
Fixes #1490
PR Checklist
Was the documentation framework updated to reflect the changes?Testing Checklist