<commit_before>import json
from hashlib import pbkdf2_hmac
from jsonschema import validate

class SecureStashError(Exception): pass

OUTER_SCHEMA = {
    "type": "object",
    "properties": {
        "hash": {"type": "string"},
        "salt": {"type": "string"},
        "iterations": {"type": "integer", "minimum":0},
        "enc_blob": {"type": "string"},
    },
    "required": ["hash","salt","iterations","enc_blob"],
    "additionalProperties": False,
}

INNER_SCHEMA = {
    "definitions": {
        "children": {
            "type": "object",
            "patternProperties": {
                ".*": {
                    "entry": {
                        "type": "object",
                        "properties": {
                            "children": {"$ref": "#/definitions/children"},
                            "value": {"type": "string"},
                        },
                        "required": ["children"],
                        "additionalProperties": False,
                    }
                }
            },
            "additionalProperties": False,
        },
    },
    "$ref": "#/definitions/children",
}


"""
Example json file:

hash_name: "sha256",
salt: "af1234fcadb",
iterations: 100000,
enc_blob: "345908abcdf4395840398acd",


Inside the encrypted blob:
<commit_msg>Fixed inner schema. Split to children and schema definitions.<commit_after>import json
from hashlib import pbkdf2_hmac
from jsonschema import validate

class SecureStashError(Exception): pass

OUTER_SCHEMA = {
    "type": "object",
    "properties": {
        "hash": {"type": "string"},
        "salt": {"type": "string"},
        "iterations": {"type": "integer", "minimum":0},
        "enc_blob": {"type": "string"},
    },
    "required": ["hash","salt","iterations","enc_blob"],
    "additionalProperties": False,
}

INNER_SCHEMA = {
    "definitions": {
        "children": {
            "type": "object",
            "patternProperties": {
                ".*": {"$ref": "#/definitions/entry"},
            },
            "additionalProperties": False,
        },
        "entry": {
            "type": "object",
            "properties": {
                "children": {"$ref": "#/definitions/children"},
                "value": {"type": "string"},
            },
            "required": ["children"],
            "additionalProperties": False,
        }
    },
    "$ref": "#/definitions/children",
}


"""
Example json file:

hash_name: "sha256",
salt: "af1234fcadb",
iterations: 100000,
enc_blob: "345908abcdf4395840398acd",


Inside the encrypted blob:

{'fraction_non_alphanumeric': 0.16918897943344974, 'fraction_numerical': 0.02405898331393093, 'mean_word_length': 2.0081680280046674, 'pattern_counts': {'":': 59, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1963370', 'n_tokens_mistral': 804, 'n_tokens_neox': 728, 'n_words': 156}