diff options
author | Christian Heimes <christian@python.org> | 2016-09-07 11:58:24 +0200 |
---|---|---|
committer | Christian Heimes <christian@python.org> | 2016-09-07 11:58:24 +0200 |
commit | 6fe2a75b645044ca2b5dac03e8d850567b547a9a (patch) | |
tree | 62e1a5edd46384ff687c96f4f94cf3b0a2bae72e /Modules/_sha3/cleanup.py | |
parent | blake2: silence two more warnings on platforms with size_t < uint64_t. Don't ... (diff) | |
download | cpython-6fe2a75b645044ca2b5dac03e8d850567b547a9a.tar.gz cpython-6fe2a75b645044ca2b5dac03e8d850567b547a9a.tar.bz2 cpython-6fe2a75b645044ca2b5dac03e8d850567b547a9a.zip |
Issue #16113: Add SHA-3 and SHAKE support to hashlib module.
Diffstat (limited to 'Modules/_sha3/cleanup.py')
-rwxr-xr-x | Modules/_sha3/cleanup.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Modules/_sha3/cleanup.py b/Modules/_sha3/cleanup.py new file mode 100755 index 00000000000..17c56b34b26 --- /dev/null +++ b/Modules/_sha3/cleanup.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# Copyright (C) 2012 Christian Heimes (christian@python.org) +# Licensed to PSF under a Contributor Agreement. +# +# cleanup Keccak sources + +import os +import re + +CPP1 = re.compile("^//(.*)") +CPP2 = re.compile("\ //(.*)") + +STATICS = ("void ", "int ", "HashReturn ", + "const UINT64 ", "UINT16 ", " int prefix##") + +HERE = os.path.dirname(os.path.abspath(__file__)) +KECCAK = os.path.join(HERE, "kcp") + +def getfiles(): + for name in os.listdir(KECCAK): + name = os.path.join(KECCAK, name) + if os.path.isfile(name): + yield name + +def cleanup(f): + buf = [] + for line in f: + # mark all functions and global data as static + #if line.startswith(STATICS): + # buf.append("static " + line) + # continue + # remove UINT64 typedef, we have our own + if line.startswith("typedef unsigned long long int"): + buf.append("/* %s */\n" % line.strip()) + continue + ## remove #include "brg_endian.h" + if "brg_endian.h" in line: + buf.append("/* %s */\n" % line.strip()) + continue + # transform C++ comments into ANSI C comments + line = CPP1.sub(r"/*\1 */\n", line) + line = CPP2.sub(r" /*\1 */\n", line) + buf.append(line) + return "".join(buf) + +for name in getfiles(): + with open(name) as f: + res = cleanup(f) + with open(name, "w") as f: + f.write(res) |