util.nonce_increment and util.wipe functions, also exported by each module for convenience.

This commit is contained in:
Leo Vasanko
2025-11-07 09:53:39 -06:00
parent 96ce7867de
commit 1dcdafa008
7 changed files with 32 additions and 13 deletions
+14 -1
View File
@@ -10,7 +10,7 @@ from typing import Protocol
from ._loader import ffi
__all__ = ["new_aligned_struct", "aligned_address", "Buffer", "nonce_increment"]
__all__ = ["new_aligned_struct", "aligned_address", "Buffer", "nonce_increment", "wipe"]
try:
from collections.abc import Buffer as _Buffer
@@ -61,3 +61,16 @@ def nonce_increment(nonce: Buffer) -> None:
n[i] += 1
return
n[i] = 0
def wipe(buffer: Buffer) -> None:
"""Set all bytes of the input buffer to zero.
Useful for securely clearing sensitive data from memory.
Args:
buffer: The buffer to wipe (modified in place).
"""
n = memoryview(buffer)
for i in range(len(n)):
n[i] = 0