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

Feeding could handle an empty buffer more gracefully #15

Closed
teeberg opened this issue Jun 21, 2017 · 4 comments
Closed

Feeding could handle an empty buffer more gracefully #15

teeberg opened this issue Jun 21, 2017 · 4 comments
Assignees
Labels

Comments

@teeberg
Copy link

teeberg commented Jun 21, 2017

The CBC encryption feeding example in the README currently reads something like:

encrypter = pyaes.Encrypter(pyaes.AESModeOfOperationCBC(key, iv))
ciphertext = encrypter.feed(plaintext)
# Make a final call to flush any remaining bytes and add paddin
ciphertext += encrypter.feed()

If you pass in an empty string as the plaintext, this results in:

.../.venv/lib/python2.7/site-packages/pyaes/blockfeeder.pyc in feed(self, data)
    163 
    164         if self._buffer is None:
--> 165             raise ValueError('already finished feeder')
    166 
    167         # Finalize; process the spare bytes we were keeping

ValueError: already finished feeder

This could be made ever so slightly more reliable by changing this line to:

if data is None:

This would make it easier to have a generic encrypt_aes function taking an arbitrary string, without having to handle an empty string as a special case.

Does that seem like a sensible approach?

@ricmoo
Copy link
Owner

ricmoo commented Jul 21, 2017

That absolutely makes sense.

Sorry this has taken so long to get to. I will add a test case this weekend for that case (to reproduce the issue), make that change, and get it updated.

@ricmoo ricmoo self-assigned this Sep 13, 2017
@ricmoo ricmoo added the bug label Sep 13, 2017
@ricmoo
Copy link
Owner

ricmoo commented Sep 20, 2017

Fixed and updated in pypi.

Thanks!

@ricmoo ricmoo closed this as completed Sep 20, 2017
@teeberg
Copy link
Author

teeberg commented Sep 20, 2017

@ricmoo thank you for the fix!

for the record, fixed in 23a1b4c

@ricmoo
Copy link
Owner

ricmoo commented Sep 21, 2017

Ah yes! Thank you for including that.

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

No branches or pull requests

2 participants