From 5b41c82f78a1dc29b5ae51c3311e8e2d8b455a1c Mon Sep 17 00:00:00 2001 From: aaronkaplan Date: Wed, 26 May 2021 12:16:11 +0200 Subject: [PATCH] Add a function to validate dnsdbflex output Signed-off-by: aaronkaplan --- misp_modules/lib/cof2misp/cof.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/misp_modules/lib/cof2misp/cof.py b/misp_modules/lib/cof2misp/cof.py index 395569e..a222a3d 100644 --- a/misp_modules/lib/cof2misp/cof.py +++ b/misp_modules/lib/cof2misp/cof.py @@ -93,6 +93,25 @@ def validate_cof(d: dict, strict=True) -> bool: else: return is_cof_valid_strict(d) +def validate_dnsdbflex(d: dict, strict=True) -> bool: + """ + Validate if dict d is valid dnsdbflex. It should looks like this: + { "rrtype": , "rrname": } + """ + if "rrname" not in d: + print("Missing MANDATORY field 'rrname'", file=sys.stderr) + return False + if not isinstance(d['rrname'], str): + print("Type error: 'rrname' is not a JSON string", file=sys.stderr) + return False + if "rrtype" not in d: + print("Missing MANDATORY field 'rrtype'", file=sys.stderr) + return False + if not isinstance(d['rrtype'], str): + print("Type error: 'rrtype' is not a JSON string", file=sys.stderr) + return False + return True + if __name__ == "__main__": # simple, poor man's unit tests.