
    Xf              	          d dl Z d dlZd dlZd dlZd dlmZmZmZmZ d dl	m
Z
  ej        e          Zej                            e
j        d          Zdee         fdZdee         ddfdZ e            Zdd
eeef         dedefdZ	 dd
eeef         deeeef                  dee         fdZ	 dd
eeef         deeef         dedefdZdS )    N)AnyDictOptionalSet)	constantszvalid_isf.hashcachereturnc                     t                      } t          j                            t                    rTt          t          d          5 }|                     t          j        |                     ddd           n# 1 swxY w Y   | S )z_Loads up the list of successfully cached json objects, so we don't need
    to revalidate them.rN)	setospathexistscached_validation_filepathopenupdatejsonload)validhashesfs     N/home/panchajanya/Development/work/volatility3/volatility3/schemas/__init__.pyload_cached_validationsr      s     uuK	w~~011 -,c22 	-aty||,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   (A<<B B validationsc                     t          t          d          5 }t          j        t	          |           |           ddd           dS # 1 swxY w Y   dS )zQRecord the cached validations, so we don't need to revalidate them in
    future.wN)r   r   r   dumplist)r   r   s     r   record_cached_validationsr      s     
(#	.	. (!	${##Q'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   #AA
A
Tinput	use_cachec                 v   |                      di                                dd          }|st                              d           dS t          j                            t          j                            t                              }t          j                            |d|z   dz             }t          j        	                    |          st                              d|            dS t          |d	          5 }t          j        |          }ddd           n# 1 swxY w Y   t          | ||          S )
z(Validates an input JSON file based upon.metadataformatNNo schema format definedFschema-.jsonSchema for format not found: r
   )getvollogdebugr   r   abspathdirname__file__joinr   r   r   r   valid)r   r   r"   basepathschema_pathsschemas          r   validater3   &   s<   YYz2&&**8T::F /000uwrwx8899H',,xV);g)EFFK7>>+&& B[BBCCCu	k3		 11              	***s   >DD#&D#r2   c                    |)|                      di                                dd          }|st                              d           dS t          j                            t          j                            t                              }t          j                            |d|z   dz             }t          j        	                    |          st                              d|            dS t          |d          5 }t          j        |          }ddd           n# 1 swxY w Y   t          j        t          t          j        | |fd	
          d                                                    S )ziConstructs the hash of the input and schema to create a unique
    identifier for a particular JSON file.Nr!   r"   r#   r$   r%   r&   r
   T)	sort_keyszutf-8)r'   r(   r)   r   r   r*   r+   r,   r-   r   r   r   r   hashlibsha1bytesdumps	hexdigest)r   r2   r"   r/   r0   r1   s         r   create_json_hashr;   6   sn   
 ~:r**..x>> 	LL344447??27??8#<#<==gll8Y-?'-IJJw~~k** 	LLFFFGGG4+s## 	"qYq\\F	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"<dj%D9997CC ikks   D""D&)D&c                 .   t          | |          }|t          v r|rdS 	 ddl}nE# t          $ r8 t                              d           t                              d           Y dS w xY w	 t                              d           |                    | |           t                              |           t                              d           n2# |j	        j
        $ r  t                              dd	           Y d
S w xY wt          t                     dS )zValidates a json schema.Tr   Nz1Dependency for validation unavailable: jsonschemaz>All validations will report success, even with malformed inputz!Validating JSON against schema...z-JSON validated against schema (result cached)zSchema validation error)exc_infoF)r;   cached_validations
jsonschemaImportErrorr(   infor)   r3   add
exceptionsSchemaErrorr   )r   r2   r   
input_hashr?   s        r   r.   r.   L   s2    "%00J'''I't   GHHHUVVVtt
8999E6***z***DEEEE ,   .>>>uu 01114s"   $ >A&%A&*A$C +C>=C>)T)N)r6   r   loggingr   typingr   r   r   r   volatility3.frameworkr   	getLogger__name__r(   r   r-   
CACHE_PATHr   strr   r   r>   boolr3   r;   r.        r   <module>rP      s  
    				 + + + + + + + + + + + + + + + + + +		8	$	$W\\)*>@UVV S    (3s8 ( ( ( ( ( -,.. + +DcN +t +t + + + +" ?C S>#+DcN#;c]   . FJ S>#'S>>B	     rO   