util.nonce_increment and util.wipe functions, also exported by each module for convenience.
This commit is contained in:
+14
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user