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

add support for update_into on CipherContext #3190

Merged
merged 23 commits into from
Feb 17, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/hazmat/primitives/symmetric-encryption.rst
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,12 @@ Interfaces
>>> iv = os.urandom(16)
>>> cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend)
>>> encryptor = cipher.encryptor()
>>> buf = bytearray(31)
>>> buf = bytearray(31) # size the buffer to b len(data) + n - 1
Copy link
Member

Choose a reason for hiding this comment

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

b len(data)?

Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand this comment :-)

>>> len_encrypted = encryptor.update_into(b"a secret message", buf)
>>> ct = bytes(buf[:len_encrypted]) + encryptor.finalize()
>>> ct = bytes(buf[:len_encrypted]) + encryptor.finalize() # get the ciphertext from the buffer reading only the bytes written to it (len_encrypted)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe put the comment on the line above the code, so it doesn't wrap so long?

>>> decryptor = cipher.decryptor()
>>> len_decrypted = decryptor.update_into(ct, buf)
>>> bytes(buf[:len_decrypted]) + decryptor.finalize()
>>> bytes(buf[:len_decrypted]) + decryptor.finalize() # get the plaintext from the buffer reading only the bytes written (len_decrypted)
'a secret message'

.. method:: finalize()
Expand Down