diff --git a/unblob/models.py b/unblob/models.py index c66c507229..011e5ac608 100644 --- a/unblob/models.py +++ b/unblob/models.py @@ -33,6 +33,13 @@ def metadata_converter(obj: Union[Dict, Instance]) -> dict: raise ValueError("Can only convert dict or Instance") +def metadata_validator(instance, attribute, value): + if attribute.name == "metadata" and isinstance(instance, Chunk): + for k, _ in value.items(): + if not isinstance(k, str): + raise TypeError("metadata keys must be string") + + @attr.define(frozen=True) class Task: path: Path @@ -100,7 +107,9 @@ class ValidChunk(Chunk): handler: "Handler" = attr.ib(init=False, eq=False) is_encrypted: bool = attr.ib(default=False) - metadata: dict = attr.ib(factory=dict, converter=metadata_converter) + metadata: dict = attr.ib( + factory=dict, converter=metadata_converter, validator=metadata_validator + ) def extract(self, inpath: Path, outdir: Path): if self.is_encrypted: