From 8d4ccb846a04c9180bf6a9f53bf6449fcb0ce1a9 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Mon, 10 Jul 2017 00:05:05 +0100 Subject: [PATCH] Split out the JSON hashing function for reuse with other caching mechanisms. --- volatility/schemas/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/volatility/schemas/__init__.py b/volatility/schemas/__init__.py index 5dc2c5297..5f9bb7ac3 100644 --- a/volatility/schemas/__init__.py +++ b/volatility/schemas/__init__.py @@ -44,9 +44,14 @@ def validate(input, use_cache = True): return valid(input, schema, use_cache) +def create_json_hash(input, schema): + """Constructs the hash of the input and schema to create a unique indentifier for a particular JSON file""" + return hashlib.sha1(bytes(json.dumps((input, schema), sort_keys = True), 'utf-8')).hexdigest() + + def valid(input, schema, use_cache = True): """Validates a json schema""" - input_hash = hashlib.sha1(bytes(json.dumps((input, schema), sort_keys = True), 'utf-8')).hexdigest() + input_hash = create_json_hash(input, schema) if input_hash in cached_validations and use_cache: return True try: