summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index fc777b82..2eb79d33 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1725,7 +1725,7 @@ def logexc(log, msg, *args):
log.debug(msg, exc_info=exc_info, *args)
-def hash_blob(blob, routine, mlen=None):
+def hash_blob(blob, routine: str, mlen=None) -> str:
hasher = hashlib.new(routine)
hasher.update(encode_text(blob))
digest = hasher.hexdigest()
@@ -1736,6 +1736,18 @@ def hash_blob(blob, routine, mlen=None):
return digest
+def hash_buffer(f: io.BufferedIOBase) -> bytes:
+ """Hash the content of a binary buffer using SHA1.
+
+ @param f: buffered binary stream to hash.
+ @return: digested data as bytes.
+ """
+ hasher = hashlib.sha1()
+ for chunk in iter(lambda: f.read(io.DEFAULT_BUFFER_SIZE), b""):
+ hasher.update(chunk)
+ return hasher.digest()
+
+
def is_user(name):
try:
if pwd.getpwnam(name):