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

Allow padding of value before encrypting #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robinvdvleuten
Copy link

As discussed in issue #99, this PR adds support of padding of the value before encrypting.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.9%) to 97.895% when pulling 2777222 on robinvdvleuten:padding into f6d17d9 on danielberkompas:master.

@danielberkompas
Copy link
Owner

Thanks! I've seen this and will review as soon as I can.

Copy link
Owner

@danielberkompas danielberkompas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Nicely done! I just had a couple requests for tests.


test "encrypts ciphertext with custom padding" do
assert ciphertext = TestVault.encrypt!("plaintext", padding: 24)
assert is_binary(ciphertext)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is pretty much identical to the test above, so all it tests is that the padding: 24 option is accepted, not that it actually pads up to 24 bytes. I think we should test that the ciphertext is 24 bytes long, if possible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! And also wondered about this while creating this text. What should be the length of the encrypted text when not taking padding into account?

test "encrypts ciphertext with default padding" do
assert ciphertext = TestVault.encrypt!("plaintext", padding: true)
assert is_binary(ciphertext)
assert ciphertext != "plaintext"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should assert that the ciphertext is 16 bytes, if possible.

|> Kernel.<>("\x80")
|> String.pad_trailing(size - 1, "\x00")
else
str
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we don't have any test coverage of this line. We should have a test that tests what happens if the string is already longer than the padding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants