aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sec_certs/serialization/schemas/__init__.py
blob: 31fd252e9a4a5e047dfa9b1e199c48ceb512cdef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import json
from importlib import resources

from jsonschema import Draft7Validator
from referencing import Registry, Resource

_schemas = ["base.json", "cc_certificate.json", "cc_dataset.json", "fips_certificate.json", "fips_dataset.json"]


def validator(for_schema: str) -> Draft7Validator:
    registry = Registry()
    for schema in _schemas:
        with resources.open_text("sec_certs.serialization.schemas", schema) as f:
            schema_json = json.load(f)
            resource = Resource.from_contents(schema_json)
            registry = resource @ registry
    return Draft7Validator(schema={"$ref": for_schema}, registry=registry)