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

View File

@@ -72,13 +72,11 @@ def nonce_increment(nonce: Buffer) -> None:
def wipe(buffer: Buffer) -> None:
"""Set all bytes of the input buffer to zero.
Useful for securely clearing sensitive data from memory.
"""Securely clearing sensitive data from memory. Sets all bytes of the buffer to 0xFF.
Args:
buffer: The buffer to wipe (modified in place).
"""
n = memoryview(buffer)
for i in range(len(n)):
n[i] = 0
# This is the fastest method I have found in Python
n = memoryview(buffer).cast("B")
n[:] = b"\xff" * len(n)