Use a much faster method to wipe buffers.

This commit is contained in:
Leo Vasanko
2025-11-09 20:38:28 -06:00
parent f5430a6ad4
commit d8a9a7ee9d
+4 -6
View File
@@ -72,13 +72,11 @@ def nonce_increment(nonce: Buffer) -> None:
def wipe(buffer: Buffer) -> None: def wipe(buffer: Buffer) -> None:
"""Set all bytes of the input buffer to zero. """Securely clearing sensitive data from memory. Sets all bytes of the buffer to 0xFF.
Useful for securely clearing sensitive data from memory.
Args: Args:
buffer: The buffer to wipe (modified in place). buffer: The buffer to wipe (modified in place).
""" """
n = memoryview(buffer) # This is the fastest method I have found in Python
for i in range(len(n)): n = memoryview(buffer).cast("B")
n[i] = 0 n[:] = b"\xff" * len(n)