step-03-validate-bin.py 875 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Step 03 - validate raw dictionary file.
  2. #
  3. # CRC32, MD5, SHA1 and SHA256 checksums for raw binary dictionary are checked.
  4. import hashlib
  5. import zlib
  6. bin_path = "dictionary.bin"
  7. with open(bin_path, "rb") as raw:
  8. data = raw.read()
  9. def check_digest(name, expected, actual):
  10. if expected == actual:
  11. print("[OK] " + name)
  12. else:
  13. print("[ERROR] " + name + " | " + expected + " != " + actual)
  14. check_digest(
  15. "CRC32", # This is the only checksum provided in RFC.
  16. "0x5136cb04",
  17. hex(zlib.crc32(data)))
  18. check_digest("MD5", "96cecd2ee7a666d5aa3627d74735b32a",
  19. hashlib.md5(data).hexdigest())
  20. check_digest("SHA1", "72b41051cb61a9281ba3c4414c289da50d9a7640",
  21. hashlib.sha1(data).hexdigest())
  22. check_digest(
  23. "SHA256",
  24. "20e42eb1b511c21806d4d227d07e5dd06877d8ce7b3a817f378f313653f35c70",
  25. hashlib.sha256(data).hexdigest())