Use a much faster method to wipe buffers.

This commit is contained in:
2025-11-10 08:38:28 +00:00
parent c6e77cac66
commit c2ac2e2790
+4 -6
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)