Christian Heimes | 121b948 | 2016-09-06 22:03:25 +0200 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | import os |
| 4 | import re |
| 5 | |
| 6 | HERE = os.path.dirname(os.path.abspath(__file__)) |
| 7 | BLAKE2 = os.path.join(HERE, 'impl') |
| 8 | |
| 9 | PUBLIC_SEARCH = re.compile(r'\ int (blake2[bs]p?[a-z_]*)\(') |
| 10 | |
| 11 | |
| 12 | def getfiles(): |
| 13 | for name in os.listdir(BLAKE2): |
| 14 | name = os.path.join(BLAKE2, name) |
| 15 | if os.path.isfile(name): |
| 16 | yield name |
| 17 | |
| 18 | |
| 19 | def find_public(): |
| 20 | public_funcs = set() |
| 21 | for name in getfiles(): |
| 22 | with open(name) as f: |
| 23 | for line in f: |
| 24 | # find public functions |
| 25 | mo = PUBLIC_SEARCH.search(line) |
| 26 | if mo: |
| 27 | public_funcs.add(mo.group(1)) |
| 28 | |
| 29 | for f in sorted(public_funcs): |
| 30 | print('#define {0:<18} PyBlake2_{0}'.format(f)) |
| 31 | |
| 32 | return public_funcs |
| 33 | |
| 34 | |
| 35 | def main(): |
| 36 | lines = [] |
| 37 | with open(os.path.join(HERE, 'blake2b_impl.c')) as f: |
| 38 | for line in f: |
| 39 | line = line.replace('blake2b', 'blake2s') |
| 40 | line = line.replace('BLAKE2b', 'BLAKE2s') |
| 41 | line = line.replace('BLAKE2B', 'BLAKE2S') |
| 42 | lines.append(line) |
| 43 | with open(os.path.join(HERE, 'blake2s_impl.c'), 'w') as f: |
| 44 | f.write(''.join(lines)) |
| 45 | # find_public() |
| 46 | |
| 47 | |
| 48 | if __name__ == '__main__': |
| 49 | main() |