Should support any buffer objects, not just bytes
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1.2k
- Forks
- 267
- Avg merge
- 42m
- Merged PRs (30d)
- 2
Description
Use ffi.from_buffer(...) for conversions, so that bytearray, memoryview and other things work too, instead of checking that the arguments are bytes instances.
I would also prefer being able to give output buffers to low level functions, for instance I had to do this hack to enable encryption without creating a new buffer. It works even in place, if ciphertext and message are the same buffer:
from nacl._sodium import ffi, lib
def encrypt_into(ciphertext, message, aad, nonce, key):
mlen = len(message)
clen = ffi.new("unsigned long long *")
ciphertext = ffi.from_buffer(ciphertext)
message = ffi.from_buffer(message)
if aad:
_aad = ffi.from_buffer(aad)
aalen = len(aad)
else:
_aad = ffi.NULL
aalen = 0
return lib.crypto_aead_chacha20poly1305_ietf_encrypt(
ciphertext, clen, message, mlen, _aad, aalen, ffi.NULL, nonce, key
)
While for most things it does not matter if copies are made and new buffers are being allocated, stream ciphers can be much faster with proper buffer management.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the low-level Python binding functions that currently require bytes and compare them with the shown ffi.from_buffer usage. Define which input and output buffer cases must work, including bytearray, memoryview, and in-place encryption, then verify those cases without unnecessary buffer allocation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cryptography
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100