Convert all input buffers to memoryview before use and use .nbytes, because len() doesn't work correctly with some buffers. Update docs with a Numpy example.

This commit is contained in:
2025-11-09 21:19:50 +00:00
parent a29405455a
commit cb0f9956c3
8 changed files with 907 additions and 458 deletions
+12
View File
@@ -243,6 +243,18 @@ For advanced use cases, the output buffer can be supplied with `into` kwarg. Any
A `TypeError` is raised if the buffer is too small. For convenience, the functions return a memoryview showing only the bytes actually written.
Foreign arrays can be used. This example fills a Numpy array with random integers.
```python
import numpy as np
from pyaegis import aegis128x4 as ciph
key, nonce = ciph.random_key(), ciph.random_nonce()
arr = np.empty(10, dtype=np.uint64) # Uninitialised integer array
ciph.stream(key, nonce, into=arr) # Fill with random bytes
print(arr)
```
In-place operations are supported when the input and the output point to the same location in memory. When using attached MAC tag, the input buffer needs to be sliced to correct length:
```python